From a5c6d5e29095ce4fa8d509453f67e1a158366297 Mon Sep 17 00:00:00 2001 From: Geevarghese V K Date: Tue, 21 Jun 2022 18:48:46 +0530 Subject: [PATCH] coverity fixes Signed-off-by: Geevarghese V K --- .../audiorenderer/include/audio_renderer_sink.h | 2 +- .../include/bluetooth_renderer_sink.h | 2 +- .../native/audiostream/include/audio_stream.h | 2 +- .../pulseaudio/src/modules/hdi/hdi_source.c | 17 ++++++++++------- .../audio_policy/server/audio_service_dump.h | 2 +- .../audio_policy/server/audio_service_dump.cpp | 2 +- .../client/audio_service_client.cpp | 10 +++++++++- 7 files changed, 24 insertions(+), 13 deletions(-) diff --git a/frameworks/native/audiorenderer/include/audio_renderer_sink.h b/frameworks/native/audiorenderer/include/audio_renderer_sink.h index db17c2c4..0dcfd60a 100644 --- a/frameworks/native/audiorenderer/include/audio_renderer_sink.h +++ b/frameworks/native/audiorenderer/include/audio_renderer_sink.h @@ -68,7 +68,7 @@ private: struct AudioManager *audioManager_; struct AudioAdapter *audioAdapter_; struct AudioRender *audioRender_; - struct AudioPort audioPort_; + struct AudioPort audioPort_ = {}; int32_t CreateRender(struct AudioPort &renderPort); int32_t InitAudioManager(); diff --git a/frameworks/native/audiorenderer/include/bluetooth_renderer_sink.h b/frameworks/native/audiorenderer/include/bluetooth_renderer_sink.h index eb013571..00ecf032 100644 --- a/frameworks/native/audiorenderer/include/bluetooth_renderer_sink.h +++ b/frameworks/native/audiorenderer/include/bluetooth_renderer_sink.h @@ -60,7 +60,7 @@ private: struct HDI::Audio_Bluetooth::AudioProxyManager *audioManager_; struct HDI::Audio_Bluetooth::AudioAdapter *audioAdapter_; struct HDI::Audio_Bluetooth::AudioRender *audioRender_; - struct HDI::Audio_Bluetooth::AudioPort audioPort; + struct HDI::Audio_Bluetooth::AudioPort audioPort = {}; void *handle_; int32_t CreateRender(struct HDI::Audio_Bluetooth::AudioPort &renderPort); diff --git a/frameworks/native/audiostream/include/audio_stream.h b/frameworks/native/audiostream/include/audio_stream.h index 37d8133e..8111a134 100644 --- a/frameworks/native/audiostream/include/audio_stream.h +++ b/frameworks/native/audiostream/include/audio_stream.h @@ -83,7 +83,7 @@ private: std::atomic isWriteInProgress_; bool resetTime_; uint64_t resetTimestamp_; - struct timespec baseTimestamp_; + struct timespec baseTimestamp_ = {0}; AudioRenderMode renderMode_; AudioCaptureMode captureMode_; std::queue freeBufferQ_; diff --git a/frameworks/native/pulseaudio/src/modules/hdi/hdi_source.c b/frameworks/native/pulseaudio/src/modules/hdi/hdi_source.c index 20046949..9be61089 100644 --- a/frameworks/native/pulseaudio/src/modules/hdi/hdi_source.c +++ b/frameworks/native/pulseaudio/src/modules/hdi/hdi_source.c @@ -227,14 +227,17 @@ static void thread_func(void *userdata) now = pa_rtclock_now(); AUDIO_DEBUG_LOG("HDI Source: now: %{public}" PRIu64 " timer_elapsed: %{public}d", now, timer_elapsed); - if (timer_elapsed && (chunk.length = pa_usec_to_bytes(now - u->timestamp, &u->source->sample_spec)) > 0) { - ret = get_capturer_frame_from_hdi(&chunk, u); - if (ret != 0) { - break; - } + if (timer_elapsed) { + chunk.length = pa_usec_to_bytes(now - u->timestamp, &u->source->sample_spec); + if (chunk.length > 0) { + ret = get_capturer_frame_from_hdi(&chunk, u); + if (ret != 0) { + break; + } - u->timestamp += pa_bytes_to_usec(chunk.length, &u->source->sample_spec); - AUDIO_DEBUG_LOG("HDI Source: new u->timestamp : %{public}" PRIu64, u->timestamp); + u->timestamp += pa_bytes_to_usec(chunk.length, &u->source->sample_spec); + AUDIO_DEBUG_LOG("HDI Source: new u->timestamp : %{public}" PRIu64, u->timestamp); + } } pa_rtpoll_set_timer_absolute(u->rtpoll, u->timestamp + u->block_usec); diff --git a/services/include/audio_policy/server/audio_service_dump.h b/services/include/audio_policy/server/audio_service_dump.h index 924f1797..d9b6ae42 100644 --- a/services/include/audio_policy/server/audio_service_dump.h +++ b/services/include/audio_policy/server/audio_service_dump.h @@ -106,7 +106,7 @@ private: bool isMainLoopStarted; bool isContextConnected; - AudioData audioData_; + AudioData audioData_ = {}; int32_t ConnectStreamToPA(); void ResetPAAudioDump(); diff --git a/services/src/audio_policy/server/audio_service_dump.cpp b/services/src/audio_policy/server/audio_service_dump.cpp index fa1cb44a..8ae715c4 100644 --- a/services/src/audio_policy/server/audio_service_dump.cpp +++ b/services/src/audio_policy/server/audio_service_dump.cpp @@ -302,7 +302,7 @@ void AudioServiceDump::PlaybackStreamDump(std::string &dumpString) AppendFormat(dumpString, "Stream Id: %s\n", (sinkInputInfo.sessionId).c_str()); AppendFormat(dumpString, "Application Name: %s\n", ((sinkInputInfo.applicationName).c_str())); AppendFormat(dumpString, "Process Id: %s\n", (sinkInputInfo.processId).c_str()); - AppendFormat(dumpString, "User Id: %d\n", sinkInputInfo.userId); + AppendFormat(dumpString, "User Id: %u\n", sinkInputInfo.userId); char *inputSampleSpec = pa_sample_spec_snprint(s, sizeof(s), &(sinkInputInfo.sampleSpec)); AppendFormat(dumpString, "Stream Configuration: %s\n", inputSampleSpec); diff --git a/services/src/audio_service/client/audio_service_client.cpp b/services/src/audio_service/client/audio_service_client.cpp index 6dbc73e2..3b659665 100644 --- a/services/src/audio_service/client/audio_service_client.cpp +++ b/services/src/audio_service/client/audio_service_client.cpp @@ -611,7 +611,15 @@ void AudioServiceClient::SetEnv() void AudioServiceClient::SetApplicationCachePath(const std::string cachePath) { AUDIO_DEBUG_LOG("SetApplicationCachePath in"); - cachePath_ = cachePath; + + char realPath[PATH_MAX] = {0x00}; + + if ((strlen(cachePath.c_str()) >= PATH_MAX) || (realpath(cachePath.c_str(), realPath) == nullptr)) { + AUDIO_ERR_LOG("Invalid cache path. err = %{public}d", errno); + return; + } + + cachePath_ = realPath; } bool AudioServiceClient::VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId)