From 8e6863e4eb299d469efcdb06998d5d47ce98a979 Mon Sep 17 00:00:00 2001 From: Kinbay_Wu Date: Tue, 29 Oct 2024 12:06:16 +0800 Subject: [PATCH] [BPM-33229] [MT-1959] Add protection code when the str is NULL Signed-off-by: Kinbay_Wu --- libbtvoemhal/bfxat100/audio_patch.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libbtvoemhal/bfxat100/audio_patch.cpp b/libbtvoemhal/bfxat100/audio_patch.cpp index fee769f..9b44037 100644 --- a/libbtvoemhal/bfxat100/audio_patch.cpp +++ b/libbtvoemhal/bfxat100/audio_patch.cpp @@ -83,7 +83,11 @@ void setEchoDecayWeight(int decay){ ALOGD("[%s] delaytime: %d", __FUNCTION__, decay); char str[64]; memset(str,0,sizeof(str)); - sprintf(str,"audio_echo_decay=%d",decay); + if(sprintf(str,"audio_echo_decay=%d",decay) < 0) { + ALOGD("Error: str is NULL"); + throw std::runtime_error("Error: str is NULL"); + return; // Exit the function if str is NULL + } try { // Check if android::aml_audioport is valid @@ -92,8 +96,14 @@ void setEchoDecayWeight(int decay){ throw std::runtime_error("android::aml_audioport is null"); } + android::String8 str8(str); + if(str8.isEmpty()) { + ALOGD("Error: str8 is empty"); + return; + } + // Call setParameters and handle the return status - android::status_t status = android::aml_audioport->setParameters(android::String8(str)); + android::status_t status = android::aml_audioport->setParameters(str8); if (status != android::NO_ERROR) { ALOGD("Failed to set parameters: status=%d", status); throw std::runtime_error("Failed to set audio parameters"); -- 2.25.1