diff --git a/frameworks/native/format.cpp b/frameworks/native/format.cpp index 5126e9f868999e407a4ebbd8d7e44e86b52bdd7e..64854dc26ff1bb1361de6008b690b13a18cca19a 100644 --- a/frameworks/native/format.cpp +++ b/frameworks/native/format.cpp @@ -61,7 +61,6 @@ int HilogShowTimeBuffer(char* buffer, int bufLen, uint32_t showFormat, { time_t now = contentOut.tv_sec; unsigned long nsecTime = contentOut.tv_nsec; - struct tm* ptm = nullptr; size_t timeLen = 0; int ret = 0; nsecTime = (now < 0) ? (NSEC - nsecTime) : nsecTime; @@ -71,24 +70,24 @@ int HilogShowTimeBuffer(char* buffer, int bufLen, uint32_t showFormat, (showFormat & (1 << MONOTONIC_SHOWFORMAT)) ? "%6lld" : "%19lld", (long long)now); timeLen += ((ret > 0) ? ret : 0); } else { - ptm = localtime(&now); - if (ptm == nullptr) { + struct tm tmLocal; + if (localtime_r(&now, &tmLocal) == nullptr) { return 0; } - timeLen = strftime(buffer, bufLen, "%m-%d %H:%M:%S", ptm); + timeLen = strftime(buffer, bufLen, "%m-%d %H:%M:%S", &tmLocal); timeLen = strlen(buffer); if (showFormat & (1 << YEAR_SHOWFORMAT)) { - timeLen = strftime(buffer, bufLen, "%Y-%m-%d %H:%M:%S", ptm); + timeLen = strftime(buffer, bufLen, "%Y-%m-%d %H:%M:%S", &tmLocal); timeLen = strlen(buffer); } if (showFormat & (1 << ZONE_SHOWFORMAT)) { - timeLen = strftime(buffer, bufLen, "%z %m-%d %H:%M:%S", ptm); + timeLen = strftime(buffer, bufLen, "%z %m-%d %H:%M:%S", &tmLocal); timeLen = strlen(buffer); } } if (showFormat & (1 << TIME_NSEC_SHOWFORMAT)) { ret = snprintf_s(buffer + timeLen, bufLen - timeLen, bufLen - timeLen - 1, - ".%09ld", nsecTime); + ".%09lu", nsecTime); timeLen += ((ret > 0) ? ret : 0); } else if (showFormat & (1 << TIME_USEC_SHOWFORMAT)) { ret = snprintf_s(buffer + timeLen, bufLen - timeLen, bufLen - timeLen - 1, diff --git a/frameworks/native/hilog_base.cpp b/frameworks/native/hilog_base.cpp index 3d66f11c47b6056f98287d5d3f99a07a0c6e0bd5..081fb1cc03e60791e619d563af6a67df6739f10f 100644 --- a/frameworks/native/hilog_base.cpp +++ b/frameworks/native/hilog_base.cpp @@ -100,7 +100,7 @@ static int CheckConnection(SocketHandler& socketHandler) return 0; } -static int SendMessage(HilogMsg *header, const char *tag, int tagLen, const char *fmt, int fmtLen) +static int SendMessage(HilogMsg *header, const char *tag, uint16_t tagLen, const char *fmt, uint16_t fmtLen) { SocketHandler socketHandler; int ret = CheckSocket(socketHandler); @@ -115,7 +115,7 @@ static int SendMessage(HilogMsg *header, const char *tag, int tagLen, const char struct timeval tv = {0}; gettimeofday(&tv, nullptr); header->tv_sec = tv.tv_sec; - header->tv_nsec = tv.tv_usec * 1000; // 1000 : usec convert to nsec + header->tv_nsec = static_cast(tv.tv_usec * 1000); // 1000 : usec convert to nsec header->len = sizeof(HilogMsg) + tagLen + fmtLen; header->tag_len = tagLen; @@ -141,15 +141,15 @@ static int HiLogBasePrintArgs(const LogType type, const LogLevel level, const un vsnprintfp_s(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, HILOG_DEFAULT_PRIVACY, fmt, ap); - int tagLen = strnlen(tag, MAX_TAG_LEN - 1); - int logLen = strnlen(buf, MAX_LOG_LEN - 1); + auto tagLen = strnlen(tag, MAX_TAG_LEN - 1); + auto logLen = strnlen(buf, MAX_LOG_LEN - 1); HilogMsg header = {0}; header.type = type; header.level = level; #ifndef __RECV_MSG_WITH_UCRED_ header.pid = getpid(); #endif - header.tid = gettid(); + header.tid = static_cast(gettid()); header.domain = domain; return SendMessage(&header, tag, tagLen + 1, buf, logLen + 1); diff --git a/frameworks/native/hilog_input_socket_client.cpp b/frameworks/native/hilog_input_socket_client.cpp index a7f57bc6041fcaa694956d6165779b7a6f981d1b..d581c53c6e58b64f6022639781f257e9a6ee28a8 100644 --- a/frameworks/native/hilog_input_socket_client.cpp +++ b/frameworks/native/hilog_input_socket_client.cpp @@ -22,13 +22,13 @@ namespace OHOS { namespace HiviewDFX { static HilogInputSocketClient g_hilogInputSocketClient; -extern "C" int HilogWriteLogMessage(HilogMsg *header, const char *tag, int tagLen, const char *fmt, int fmtLen) +extern "C" int HilogWriteLogMessage(HilogMsg *header, const char *tag, uint16_t tagLen, const char *fmt, uint16_t fmtLen) { return g_hilogInputSocketClient.WriteLogMessage(header, tag, tagLen, fmt, fmtLen); } -int HilogInputSocketClient::WriteLogMessage(HilogMsg *header, const char *tag, int tagLen, const char *fmt, - int fmtLen) +int HilogInputSocketClient::WriteLogMessage(HilogMsg *header, const char *tag, uint16_t tagLen, const char *fmt, + uint16_t fmtLen) { int ret = CheckSocket(); if (ret < 0) { @@ -38,7 +38,7 @@ int HilogInputSocketClient::WriteLogMessage(HilogMsg *header, const char *tag, i struct timeval tv = {0}; gettimeofday(&tv, nullptr); header->tv_sec = tv.tv_sec; - header->tv_nsec = tv.tv_usec * 1000; // 1000 : usec convert to nsec + header->tv_nsec = static_cast(tv.tv_usec * 1000); // 1000 : usec convert to nsec header->len = sizeof(HilogMsg) + tagLen + fmtLen; header->tag_len = tagLen; diff --git a/frameworks/native/hilog_printf.cpp b/frameworks/native/hilog_printf.cpp index 224b3ca0565378479cf97079f604ae6de281f993..e6d523df25fa0dacf752c90e8aa9bbc4b1e007f6 100644 --- a/frameworks/native/hilog_printf.cpp +++ b/frameworks/native/hilog_printf.cpp @@ -232,7 +232,7 @@ int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int /* format log string */ debug = IsDebugOn(); priv = (!debug) && IsPrivateSwitchOn(); - + #ifdef __clang__ /* code specific to clang compiler */ #pragma clang diagnostic push @@ -250,14 +250,14 @@ int HiLogPrintArgs(const LogType type, const LogLevel level, const unsigned int #endif /* fill header info */ - int tagLen = strnlen(tag, MAX_TAG_LEN - 1); - int logLen = strnlen(buf, MAX_LOG_LEN - 1); + auto tagLen = strnlen(tag, MAX_TAG_LEN - 1); + auto logLen = strnlen(buf, MAX_LOG_LEN - 1); header.type = type; header.level = level; #ifndef __RECV_MSG_WITH_UCRED_ header.pid = getpid(); #endif - header.tid = syscall(SYS_gettid); + header.tid = static_cast(syscall(SYS_gettid)); header.domain = domain; /* flow control */ diff --git a/frameworks/native/include/hilog_input_socket_client.h b/frameworks/native/include/hilog_input_socket_client.h index bd4c4a22e1bd502d84977325067ed0839aea7a1b..5c55515f1b8a79d31b471a8187f47e80dbd96fcf 100644 --- a/frameworks/native/include/hilog_input_socket_client.h +++ b/frameworks/native/include/hilog_input_socket_client.h @@ -30,5 +30,6 @@ public: } // namespace HiviewDFX } // namespace OHOS -extern "C" int HilogWriteLogMessage(HilogMsg *header, const char *tag, int tagLen, const char *fmt, int fmtLen); +extern "C" int HilogWriteLogMessage(HilogMsg *header, const char *tag, uint16_t tagLen, const char *fmt, + uint16_t fmtLen); #endif /* HILOG_INPUT_SOCKET_CLIENT_H */ diff --git a/frameworks/native/seq_packet_socket_server.cpp b/frameworks/native/seq_packet_socket_server.cpp index 8b2ae34bf87a6600314c2fe561e0f337c8fc7bad..0793e7e0c47511729ef1ad3d409888bc2fb98d81 100644 --- a/frameworks/native/seq_packet_socket_server.cpp +++ b/frameworks/native/seq_packet_socket_server.cpp @@ -27,7 +27,9 @@ int SeqPacketSocketServer::StartAcceptingConnection(AcceptingHandler onAccepted) if (listeningStatus < 0) { #ifdef DEBUG std::cerr << "Socket listen failed: " << listeningStatus << "\n"; - std::cerr << strerror(listeningStatus) << "\n"; + constexpr int bufSize = 1024; + char buf[bufSize] = { 0 }; + std::cerr << (strerror_r(listeningStatus, buf, bufSize) == 0 ? buf : "Unknown errno") << "\n"; #endif return listeningStatus; } @@ -46,7 +48,9 @@ int SeqPacketSocketServer::AcceptingLoop(AcceptingHandler func) int acceptError = errno; #ifdef DEBUG std::cerr << "Socket accept failed: " << acceptError << "\n"; - std::cerr <(len); int midRes = 0; if (data == nullptr) { diff --git a/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp b/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp index e686ac3152066e62c07893e6932ac2a453c4971e..e8a991b2e3a3275f38add052fdca118f200388fd 100644 --- a/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp +++ b/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp @@ -45,8 +45,8 @@ void ParseLogContent(string& formatStr, vector& params, string& logConte ret += formatStr; return; } - int32_t size = params.size(); - int32_t len = formatStr.size(); + auto size = params.size(); + auto len = formatStr.size(); int32_t pos = 0; int32_t count = 0; bool debug = IsDebugOn(); diff --git a/services/hilogd/cmd_executor.cpp b/services/hilogd/cmd_executor.cpp index 78bfeb90c8e7ec9717cf7b5fd822666c457cf7c4..fb18dcfd8772d70380e19f33b310f398eef81704 100644 --- a/services/hilogd/cmd_executor.cpp +++ b/services/hilogd/cmd_executor.cpp @@ -92,7 +92,9 @@ void CmdExecutor::MainLoop() } else { int acceptError = errno; std::cerr << "Socket accept failed: " << acceptError << "\n"; - std::cerr << strerror(acceptError) << "\n"; + constexpr int bufSize = 1024; + char buf[bufSize] = { 0 }; + std::cerr << (strerror_r(acceptError, buf, bufSize) == 0 ? buf : "Unknown errno") << "\n"; break; } } diff --git a/services/hilogd/flow_control_init.cpp b/services/hilogd/flow_control_init.cpp index caf40b9c72e952e801164bf13fc3a51eb504d555..3d0540c7df4818b822c79f6f2b2b46c6386a416f 100644 --- a/services/hilogd/flow_control_init.cpp +++ b/services/hilogd/flow_control_init.cpp @@ -112,8 +112,8 @@ void ParseDomainQuota(std::string &domainStr) return; } peakStr = domainStr.substr(domainNameEnd); - uint32_t domain = std::stoi(domainIdStr, nullptr, 0); - uint32_t peak = std::stoi(peakStr, nullptr, 0); + uint32_t domain = static_cast(std::stoi(domainIdStr, nullptr, 0)); + uint32_t peak = static_cast(std::stoi(peakStr, nullptr, 0)); if (domain <= 0 || peak <= 0) { return; } @@ -167,7 +167,7 @@ int FlowCtrlDomain(HilogMsg* hilogMsg) std::unordered_map::iterator it; uint32_t domain = hilogMsg->domain; uint32_t domainId = (domain & DOMAIN_FILTER) >> DOMAIN_FILTER_SUBSYSTEM; - int logLen = hilogMsg->len - sizeof(HilogMsg) - 1 - 1; /* quota length exclude '\0' of tag and log content */ + auto logLen = hilogMsg->len - sizeof(HilogMsg) - 1 - 1; /* quota length exclude '\0' of tag and log content */ int ret = 0; it = g_domainMap.find(domainId); if (it != g_domainMap.end()) { @@ -185,7 +185,7 @@ int FlowCtrlDomain(HilogMsg* hilogMsg) } else { /* new statistic period */ it->second->startTime = tsNow; it->second->sumLen = logLen; - ret = it->second->dropped; + ret = static_cast(it->second->dropped); it->second->dropped = 0; } } diff --git a/services/hilogd/include/log_buffer.h b/services/hilogd/include/log_buffer.h index 4e676ea44ae719c98813e7d16070c00a3a2bba5b..46919c14b8e5865ac56e73c3bee24237489559b3 100644 --- a/services/hilogd/include/log_buffer.h +++ b/services/hilogd/include/log_buffer.h @@ -43,9 +43,9 @@ public: ReaderId CreateBufReader(std::function onNewDataCallback); void RemoveBufReader(const ReaderId& id); - size_t Delete(uint16_t logType); - size_t GetBuffLen(uint16_t logType); - size_t SetBuffLen(uint16_t logType, uint64_t buffSize); + int32_t Delete(uint16_t logType); + int64_t GetBuffLen(uint16_t logType); + int32_t SetBuffLen(uint16_t logType, uint64_t buffSize); int32_t GetStatisticInfoByLog(uint16_t logType, uint64_t& printLen, uint64_t& cacheLen, int32_t& dropped); int32_t GetStatisticInfoByDomain(uint32_t domain, uint64_t& printLen, uint64_t& cacheLen, int32_t& dropped); int32_t ClearStatisticInfoByLog(uint16_t logType); diff --git a/services/hilogd/include/log_data.h b/services/hilogd/include/log_data.h index 15446464213c56a5abfad634b59c51b704ee7d21..bd05c9b70bc5194f764023e5f24c00f6bc3885eb 100644 --- a/services/hilogd/include/log_data.h +++ b/services/hilogd/include/log_data.h @@ -77,7 +77,7 @@ struct HilogData { HilogData(HilogData&& cpy) { - std::memcpy(this, &cpy, sizeof(HilogData)); + std::memcpy_s(this, sizeof(HilogData), &cpy, sizeof(HilogData)); cpy.tag = nullptr; cpy.content = nullptr; } diff --git a/services/hilogd/kmsg_parser.cpp b/services/hilogd/kmsg_parser.cpp index c7f763e648dbd731607fc3542a37748192d54422..8021c627eb0f65575ca01850a9321b596a72bfc5 100644 --- a/services/hilogd/kmsg_parser.cpp +++ b/services/hilogd/kmsg_parser.cpp @@ -138,7 +138,7 @@ std::optional KmsgParser::ParseKmsg(const std::vector& km uint32_t mpid = ParsePid(kmsgStr); // If there are some other content wrapped in square brackets "[]", parse it as tag // Otherwise, use default tag "kmsg" - int tagLen = 0; + size_t tagLen = 0; std::string tagStr = ParseTag(kmsgStr); if (!tagStr.empty()) { tagLen = tagStr.size(); @@ -153,8 +153,8 @@ std::optional KmsgParser::ParseKmsg(const std::vector& km } } // Now build HilogMsg and insert it into buffer - int len = kmsgStr.size() + 1; - int msgLen = sizeof(HilogMsg) + tagLen + len + 1; + auto len = kmsgStr.size() + 1; + auto msgLen = sizeof(HilogMsg) + tagLen + len + 1; HilogMsgWrapper msgWrap((std::vector(msgLen, '\0'))); HilogMsg& msg = msgWrap.GetHilogMsg(); msg.len = msgLen; @@ -165,7 +165,7 @@ std::optional KmsgParser::ParseKmsg(const std::vector& km time_point logtime = BootTime() + microseconds{timestamp}; struct timespec logts = TimepointToTimespec(logtime); msg.tv_sec = logts.tv_sec; - msg.tv_nsec = logts.tv_nsec; + msg.tv_nsec = static_cast(logts.tv_nsec); msg.pid = mpid; msg.tid = mpid; if (strncpy_s(msg.tag, tagLen + 1, mtag.data(), tagLen) != 0) { diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index 79d36ae1a7831116e1d3552d31ce1fe6a3d2f750..b0a6de2ba65ca47e8b60bfef0bb0e7d538c1f7a0 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -26,7 +26,7 @@ using namespace std; const float DROP_RATIO = 0.05; static int g_maxBufferSize = 4194304; -static int g_maxBufferSizeByType[LOG_TYPE_MAX] = {262144, 262144, 262144, 262144, 262144}; +static size_t g_maxBufferSizeByType[LOG_TYPE_MAX] = {262144, 262144, 262144, 262144, 262144}; const int DOMAIN_STRICT_MASK = 0xd000000; const int DOMAIN_FUZZY_MASK = 0xdffff; const int DOMAIN_MODULE_BITS = 8; @@ -58,7 +58,7 @@ size_t HilogBuffer::Insert(const HilogMsg& msg) std::unique_lock lock(hilogBufferMutex); // Delete old entries when full - if (elemSize + sizeByType[msg.type] >= (size_t)g_maxBufferSizeByType[msg.type]) { + if (elemSize + sizeByType[msg.type] >= g_maxBufferSizeByType[msg.type]) { // Drop 5% of maximum log when full std::list::iterator it = msgList.begin(); while (sizeByType[msg.type] > g_maxBufferSizeByType[msg.type] * (1 - DROP_RATIO) && @@ -75,7 +75,7 @@ size_t HilogBuffer::Insert(const HilogMsg& msg) } // Re-confirm if enough elements has been removed - if (sizeByType[msg.type] >= (size_t)g_maxBufferSizeByType[msg.type]) { + if (sizeByType[msg.type] >= g_maxBufferSizeByType[msg.type]) { std::cout << "Failed to clean old logs." << std::endl; } } @@ -142,7 +142,7 @@ void HilogBuffer::UpdateStatistics(const HilogData& logData) } } -size_t HilogBuffer::Delete(uint16_t logType) +int32_t HilogBuffer::Delete(uint16_t logType) { std::list &msgList = (logType == (0b01 << LOG_KMSG)) ? hilogKlogList : hilogDataList; if (logType >= LOG_TYPE_MAX) { @@ -230,7 +230,7 @@ std::shared_ptr HilogBuffer::GetReader(const ReaderId return std::shared_ptr(); } -size_t HilogBuffer::GetBuffLen(uint16_t logType) +int64_t HilogBuffer::GetBuffLen(uint16_t logType) { if (logType >= LOG_TYPE_MAX) { return ERR_LOG_TYPE_INVALID; @@ -239,7 +239,7 @@ size_t HilogBuffer::GetBuffLen(uint16_t logType) return buffSize; } -size_t HilogBuffer::SetBuffLen(uint16_t logType, uint64_t buffSize) +int32_t HilogBuffer::SetBuffLen(uint16_t logType, uint64_t buffSize) { if (logType >= LOG_TYPE_MAX) { return ERR_LOG_TYPE_INVALID; diff --git a/services/hilogd/log_compress.cpp b/services/hilogd/log_compress.cpp index 78ac60621e2a691236bdf459d7a9033c2adf9743..d64d4f5f334069e64a2fde6523a428b649da30e5 100644 --- a/services/hilogd/log_compress.cpp +++ b/services/hilogd/log_compress.cpp @@ -44,8 +44,8 @@ int ZlibCompress::Compress(const LogPersisterBuffer &inBuffer, LogPersisterBuffe return -1; } size_t const toRead = CHUNK; - auto src_pos = 0; - auto dst_pos = 0; + size_t src_pos = 0; + size_t dst_pos = 0; size_t read = inBuffer.offset; int flush = 0; cStream.zalloc = Z_NULL; diff --git a/services/hilogd/log_kmsg.cpp b/services/hilogd/log_kmsg.cpp index 2ddd95586c065cf83083cefcdd54ac72ce48f675..97c636c72c9e5d7b2b7f18d9f6765de9e10b1145 100644 --- a/services/hilogd/log_kmsg.cpp +++ b/services/hilogd/log_kmsg.cpp @@ -57,7 +57,10 @@ int LogKmsg::LinuxReadAllKmsg() const ssize_t maxFailTime = 10; kmsgCtl = GetControlFile("/dev/kmsg"); if (kmsgCtl < 0) { - std::cout << "Cannot open kmsg! Err=" << strerror(errno) << std::endl; + constexpr int bufSize = 1024; + char buf[bufSize] = { 0 }; + std::cout << "Cannot open kmsg! Err=" << + (strerror_r(acceptError, buf, bufSize) == 0 ? buf : "Unknown errno") << std::endl; return -1; } std::unique_ptr parser = std::make_unique(); diff --git a/services/hilogd/log_persister.cpp b/services/hilogd/log_persister.cpp index bcd27daf4c5bab8bef81ccbbbca0ac1a34114d15..4466b9e0d0f416d26a7c3d50c604605339922244 100644 --- a/services/hilogd/log_persister.cpp +++ b/services/hilogd/log_persister.cpp @@ -66,6 +66,7 @@ std::shared_ptr LogPersister::CreateLogPersister(HilogBuffer &buff LogPersister::LogPersister(HilogBuffer &buffer) : m_hilogBuffer(buffer) { + m_mappedPlainLogFile = nullptr; m_bufReader = m_hilogBuffer.CreateBufReader([this]() { NotifyNewLogAvailable(); }); } diff --git a/services/hilogd/service_controller.cpp b/services/hilogd/service_controller.cpp index 38c9435d6f9b2b3d51b03811a00401d224933e69..2d740d887560f9f6adcbe9b2b7764bea6cd9f2f1 100644 --- a/services/hilogd/service_controller.cpp +++ b/services/hilogd/service_controller.cpp @@ -286,7 +286,7 @@ void ServiceController::HandleBufferSizeRequest(const PacketBuf& rawData) int64_t buffLen = m_hilogBuffer.GetBuffLen(requestMsg->logType); if (pBuffSizeRst) { pBuffSizeRst->logType = requestMsg->logType; - pBuffSizeRst->buffSize = buffLen; + pBuffSizeRst->buffSize = static_cast(buffLen); pBuffSizeRst->result = (buffLen < 0) ? buffLen : RET_SUCCESS; pBuffSizeRst++; } diff --git a/services/hilogtool/log_controller.cpp b/services/hilogtool/log_controller.cpp index cb27e04b5362b7b741c0fdb598d72cee356b7cd4..66ac7a4459aada70740a5c5d470f116039aa80c4 100644 --- a/services/hilogtool/log_controller.cpp +++ b/services/hilogtool/log_controller.cpp @@ -93,7 +93,7 @@ uint16_t GetLogType(const string& logTypeStr) uint64_t GetBuffSize(const string& buffSizeStr) { uint64_t index = buffSizeStr.size() - 1; - uint64_t buffSize; + long int buffSize; std::regex reg("[0-9]+[bBkKmMgGtT]?"); if (!std::regex_match(buffSizeStr, reg)) { std::cout << ParseErrorCode(ERR_BUFF_SIZE_INVALID) << std::endl; @@ -112,7 +112,7 @@ uint64_t GetBuffSize(const string& buffSizeStr) } else { buffSize = stol(buffSizeStr.substr(0, index + 1)); } - return buffSize; + return static_cast(buffSize); } uint16_t GetCompressAlg(const std::string& pressAlg) @@ -223,7 +223,9 @@ void LogQueryResponseOp(SeqPacketSocketClient& controller, char* recvBuffer, uin while(1) { std::fill_n(recvBuffer, bufLen, 0); if (controller.RecvMsg(recvBuffer, bufLen) == 0) { - fprintf(stderr, "Unexpected EOF %s\n", strerror(errno)); + constexpr int bufSize = 1024; + char buf[bufSize] = { 0 }; + fprintf(stderr, "Unexpected EOF %s\n", strerror_r(errno, buf, bufSize) == 0 ? buf : "Unknown errno"); exit(1); return; } @@ -419,10 +421,10 @@ int32_t LogPersistOp(SeqPacketSocketClient& controller, uint8_t msgCmd, LogPersi } if (pLogPersistStartMsg->logType == (0b01 << LOG_KMSG)) { pLogPersistStartMsg->jobId = (logPersistParam->jobIdStr == "") ? DEFAULT_KMSG_JOBID - : stoi(logPersistParam->jobIdStr); + : static_cast(stoi(logPersistParam->jobIdStr)); } else { pLogPersistStartMsg->jobId = (logPersistParam->jobIdStr == "") ? DEFAULT_JOBID - : stoi(logPersistParam->jobIdStr); + : static_cast(stoi(logPersistParam->jobIdStr)); } if (pLogPersistStartMsg->jobId <= 0) { cout << ParseErrorCode(ERR_LOG_PERSIST_JOBID_INVALID) << endl; @@ -433,7 +435,7 @@ int32_t LogPersistOp(SeqPacketSocketClient& controller, uint8_t msgCmd, LogPersi pLogPersistStartMsg->fileSize = (logPersistParam->fileSizeStr == "") ? fileSizeDefault : GetBuffSize( logPersistParam->fileSizeStr); pLogPersistStartMsg->fileNum = (logPersistParam->fileNumStr == "") ? fileNumDefault - : stoi(logPersistParam->fileNumStr); + : static_cast(stoi(logPersistParam->fileNumStr)); if (logPersistParam->fileNameStr.size() > FILE_PATH_MAX_LEN) { cout << ParseErrorCode(ERR_LOG_PERSIST_FILE_NAME_INVALID) << endl; return RET_FAIL; @@ -462,7 +464,7 @@ int32_t LogPersistOp(SeqPacketSocketClient& controller, uint8_t msgCmd, LogPersi return RET_FAIL; } for (iter = 0; iter < jobIdNum; iter++) { - pLogPersistStopMsg->jobId = stoi(vecJobId[iter]); + pLogPersistStopMsg->jobId = static_cast(stoi(vecJobId[iter])); pLogPersistStopMsg++; } SetMsgHead(&pLogPersistStopReq->msgHeader, msgCmd, sizeof(LogPersistStopMsg) * jobIdNum); @@ -603,14 +605,14 @@ int32_t SetPropertiesOp(SeqPacketSocketClient& controller, uint8_t operationType int MultiQuerySplit(const std::string& src, const char& delim, std::vector& vecSplit) { - int srcSize = src.length(); - int findPos = 0; - int getPos = 0; + auto srcSize = src.length(); + string::size_type findPos = 0; + string::size_type getPos = 0; vecSplit.clear(); while (getPos < srcSize) { findPos = src.find(delim, findPos); - if (-1 == findPos) { + if (string::npos == findPos) { if (getPos < srcSize) { vecSplit.push_back(src.substr(getPos, srcSize - getPos)); return 0; diff --git a/services/hilogtool/log_display.cpp b/services/hilogtool/log_display.cpp index 3354e078fa6b9e21fd8eae45170b352cafa6779b..4e0a76a95536cd6350f047537d632efbcd6a3175 100644 --- a/services/hilogtool/log_display.cpp +++ b/services/hilogtool/log_display.cpp @@ -68,7 +68,7 @@ unordered_map errorMsg {ERR_KMSG_SWITCH_VALUE_INVALID, "Invalid kmsg switch value, valid:on/off"}, {ERR_LOG_FILE_NUM_INVALID, "Invalid log number, log number should be more than " + to_string(MIN_LOG_FILE_NUM) + " and less than " + to_string(MAX_LOG_FILE_NUM)}, -}; +}; string ParseErrorCode(ErrorCode errorCode) { @@ -476,7 +476,7 @@ void HilogShowLog(uint32_t showFormat, HilogDataMessage* data, const HilogArgs* showBuffer.tag_len = data->tag_len; showBuffer.tv_sec = data->tv_sec; showBuffer.tv_nsec = data->tv_nsec; - int offset = data->tag_len; + auto offset = data->tag_len; const char *dataBegin = data->data + offset; char *dataPos = data->data + offset; while (*dataPos != 0) { diff --git a/services/hilogtool/main.cpp b/services/hilogtool/main.cpp index d35e9208efb3d16aa5aafd4740487614afad926a..7eca765b3bed04ea3c101174b5904f67ffabb46f 100644 --- a/services/hilogtool/main.cpp +++ b/services/hilogtool/main.cpp @@ -115,7 +115,7 @@ static void Helper() ); } -static int GetTypes(HilogArgs context, const string& typesArgs, bool exclude = false) +static uint16_t GetTypes(HilogArgs context, const string& typesArgs, bool exclude = false) { uint16_t types = 0; if (exclude) { @@ -138,7 +138,7 @@ static int GetTypes(HilogArgs context, const string& typesArgs, bool exclude = f return types; } -static int GetLevels(HilogArgs context, const string& levelsArgs, bool exclude = false) +static uint16_t GetLevels(HilogArgs context, const string& levelsArgs, bool exclude = false) { uint16_t levels = 0; if (exclude) { @@ -230,10 +230,10 @@ int HilogEntry(int argc, char* argv[]) context.regexArgs = optarg; break; case 'a': - context.headLines = atoi(optarg); + context.headLines = static_cast(atoi(optarg)); break; case 'z': - context.tailLines = atoi(optarg); + context.tailLines = static_cast(atoi(optarg)); context.noBlockMode = 1; break; case 't': @@ -595,9 +595,11 @@ int HilogEntry(int argc, char* argv[]) char recvBuffer[RECV_BUF_LEN] = {0}; if (controller.RecvMsg(recvBuffer, RECV_BUF_LEN) == 0) { - fprintf(stderr, "Unexpected EOF %s\n", strerror(errno)); - exit(1); - return 0; + constexpr int bufSize = 1024; + char buf[bufSize] = { 0 }; + fprintf(stderr, "Unexpected EOF %s\n", strerror_r(errno, buf, bufSize) == 0 ? buf : "Unknown errno"); + exit(1); + return 0; } MessageHeader* msgHeader = reinterpret_cast(recvBuffer);