diff --git a/frameworks/featured/hiview_log.c b/frameworks/featured/hiview_log.c index 41d191c3492c0395bc39deaa9fbfb4fd990dff09..d9f7f9e02ee1962f4c532bcae320aaac8591e231 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 c0c45a19b0e8c7cac562a807d2d3b5d29ff8f8bf..7c757697d290dde5a40cde31eb8b6889288b1b7d 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;