From 62e37b9dda321d3a4f27232a7e72a34c777988c4 Mon Sep 17 00:00:00 2001 From: PeterKeyboard Date: Tue, 18 Apr 2023 02:07:41 +0800 Subject: [PATCH] [HUST CSE]fix potential overflow of unsigned Signed-off-by: PeterKeyboard --- .../native/audiorenderer/test/example/audio_voip_test.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frameworks/native/audiorenderer/test/example/audio_voip_test.cpp b/frameworks/native/audiorenderer/test/example/audio_voip_test.cpp index 752adfce5e..95d47138c2 100644 --- a/frameworks/native/audiorenderer/test/example/audio_voip_test.cpp +++ b/frameworks/native/audiorenderer/test/example/audio_voip_test.cpp @@ -213,17 +213,18 @@ public: size_t numBuffersToCapture = 256; while (numBuffersToCapture) { size_t bytesRead = 0; + int32_t readFail = 0; while (bytesRead < bufferLen) { int32_t len = audioCapturer->Read(*(buffer.get() + bytesRead), bufferLen - bytesRead, isBlocking); if (len >= 0) { bytesRead += len; } else { - bytesRead = len; + readFail = len; break; } } - if (bytesRead < 0) { - AUDIO_ERR_LOG("Bytes read failed. error code %{public}zu", bytesRead); + if (readFail < 0) { + AUDIO_ERR_LOG("Bytes read failed. error code %{public}zu", readFail); break; } else if (bytesRead == 0) { continue; -- Gitee