From b7f9266284013832a75f6f844190e2d3048f5824 Mon Sep 17 00:00:00 2001 From: liuyifei Date: Sat, 22 Feb 2025 08:37:34 +0000 Subject: [PATCH] =?UTF-8?q?hilog=5Flite=E5=91=8A=E8=AD=A6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuyifei --- frameworks/featured/hiview_log.c | 12 +++++++++--- frameworks/mini/hiview_output_log.c | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/frameworks/featured/hiview_log.c b/frameworks/featured/hiview_log.c index 41d191c..d9f7f9e 100644 --- a/frameworks/featured/hiview_log.c +++ b/frameworks/featured/hiview_log.c @@ -142,8 +142,12 @@ int SecPutWcharStrEndingZero(SecPrintfStream *str, int zeroNum) int succeed = 0; int i; - for (i = 0; i < zeroNum && (SECUREC_PUTC_ZERO(str) != EOF); ++i) { + for (i = 0; i < zeroNum; ++i) { + if (SECUREC_PUTC_ZERO(str) == EOF) { + break; + } } + if (i == zeroNum) { succeed = 1; } @@ -1414,8 +1418,10 @@ int HiLogSecVsnprintfImpl(char *string, size_t count, bool isDebugMode, const ch str.cur = string; retVal = HiLogSecOutputS(&str, isDebugMode, format, arglist); - if ((retVal >= 0) && (SECUREC_PUTC_ZERO(&str) != EOF)) { - return (retVal); + if (retVal >= 0) { + if (SECUREC_PUTC_ZERO(&str) != EOF) { + return retVal; + } } else if (str.count < 0) { /* the buffer was too small; we return truncation */ string[count - 1] = 0; diff --git a/frameworks/mini/hiview_output_log.c b/frameworks/mini/hiview_output_log.c index c0c45a1..7c75769 100644 --- a/frameworks/mini/hiview_output_log.c +++ b/frameworks/mini/hiview_output_log.c @@ -405,7 +405,7 @@ static int32 LogCommonFmt(char *outStr, int32 outStrLen, const HiLogCommon *comm time = commonContentPtr->time; localtime_r(&time, &nowTime); - month = nowTime.tm_mon + 1; + month = (uint32)(nowTime.tm_mon + 1); day = nowTime.tm_mday; hour = nowTime.tm_hour; min = nowTime.tm_min; @@ -480,7 +480,7 @@ static void RemovePrivacyFmt(const char* fmtStr, size_t fmtLen, char* arr, size_ static const int privateLen = 9; size_t writePos = 0; size_t pos = 0; - for (; pos < fmtLen; ++pos) { + for (; pos < fmtLen && writePos < arrLen; ++pos) { arr[writePos++] = fmtStr[pos]; if (fmtStr[pos] != '%') { continue; @@ -491,7 +491,7 @@ static void RemovePrivacyFmt(const char* fmtStr, size_t fmtLen, char* arr, size_ pos += privateLen; } } - while (pos < fmtLen) { + while (pos < fmtLen && writePos < arrLen) { arr[writePos++] = fmtStr[pos]; } arr[writePos] = 0; -- Gitee