diff --git a/core/common/BoostRegexValidator.cpp b/core/common/BoostRegexValidator.cpp index 6a43c4fa13..b3a8fd872e 100644 --- a/core/common/BoostRegexValidator.cpp +++ b/core/common/BoostRegexValidator.cpp @@ -89,17 +89,17 @@ int main(int argc, char* argv[]) // argv is logFile,logBeginReg,logRegex } } else { Json::Value jsonResult; - Json::FastWriter jsonWriter; jsonResult["result"]["state"] = false; jsonResult["result"]["content"] = "argument's format is not correct"; - cout << jsonWriter.write(jsonResult); + Json::StreamWriterBuilder writerBuilder; + cout << Json::writeString(writerBuilder, jsonResult); } return 0; } void checkFilterRegex(const string& logFile, const string& logRegex) { Json::Value jsonResult; Json::Value jsonRoot; - Json::FastWriter jsonWriter; + Json::StreamWriterBuilder writerBuilder; try { boost::regex reg(logRegex); boost::match_results what; @@ -111,12 +111,12 @@ void checkFilterRegex(const string& logFile, const string& logRegex) { jsonRoot["content"] = what.str(); } jsonResult["result"] = jsonRoot; - cout << jsonWriter.write(jsonResult); + cout << Json::writeString(writerBuilder, jsonResult); } catch (boost::regex_error& e) { jsonRoot["state"] = "error"; jsonRoot["content"] = "过滤正则表达式错误!"; jsonResult["result"] = jsonRoot; - cout << jsonWriter.write(jsonResult); + cout << Json::writeString(writerBuilder, jsonResult); return; } } @@ -124,7 +124,7 @@ void checkFilterRegex(const string& logFile, const string& logRegex) { void checkRegex(const string& logFile, const string& logBeginReg, const string& logRegex) { Json::Value jsonResult; Json::Value jsonRoot; - Json::FastWriter jsonWriter; + Json::StreamWriterBuilder writerBuilder; try { boost::regex reg(logRegex); boost::match_results what; @@ -151,18 +151,18 @@ void checkRegex(const string& logFile, const string& logBeginReg, const string& jsonRoot["content"] = content; } jsonResult["result"] = jsonRoot; - cout << jsonWriter.write(jsonResult); + cout << Json::writeString(writerBuilder, jsonResult); } catch (boost::regex_error& e) { jsonRoot["state"] = "error"; jsonRoot["content"] = "日志内容正则表达式错误!"; jsonResult["result"] = jsonRoot; - cout << jsonWriter.write(jsonResult); + cout << Json::writeString(writerBuilder, jsonResult); return; } } vector checkLogBeginReg(const string& logFile, const string& logBeginReg, const bool display) { - Json::FastWriter jsonWriter; + Json::StreamWriterBuilder writerBuilder; Json::Value jsonRoot; Json::Value jsonResult; Json::Value jsonPosition; @@ -203,13 +203,13 @@ vector checkLogBeginReg(const string& logFile, const string& logBeginReg jsonRoot["result"]["position"] = jsonPosition; if (display) - cout << jsonWriter.write(jsonRoot); + cout << Json::writeString(writerBuilder, jsonRoot); return outputVector; } catch (boost::regex_error& e) { jsonRoot["state"] = "error"; jsonRoot["content"] = "日志起始匹配正则表达式错误!"; jsonResult["result"] = jsonRoot; - cout << jsonWriter.write(jsonResult); + cout << Json::writeString(writerBuilder, jsonResult); return resultVector; } } diff --git a/core/common/Lock.h b/core/common/Lock.h index b88da245ab..3f90e4ed82 100644 --- a/core/common/Lock.h +++ b/core/common/Lock.h @@ -16,6 +16,12 @@ #pragma once #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-local-typedefs" +#include +#include +#include +#pragma GCC diagnostic pop #include #include #ifdef _MSC_VER diff --git a/core/observer/metas/ConnectionMetaManager.cpp b/core/observer/metas/ConnectionMetaManager.cpp index 462529a0c5..5def0db777 100644 --- a/core/observer/metas/ConnectionMetaManager.cpp +++ b/core/observer/metas/ConnectionMetaManager.cpp @@ -358,6 +358,10 @@ bool ExtractDiagMsg(const inet_diag_msg& msg, .IPV4 = msg.id.idiag_dst[0], }}; } else if (msg.idiag_family == AF_INET6) { +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ info->localAddr = SockAddress{.Type = SockAddressType_IPV6, .Addr = SockAddressDetail{ .IPV6 = {((uint64_t*)msg.id.idiag_src)[0], ((uint64_t*)msg.id.idiag_src)[1]}, @@ -366,6 +370,9 @@ bool ExtractDiagMsg(const inet_diag_msg& msg, .Addr = SockAddressDetail{ .IPV6 = {((uint64_t*)msg.id.idiag_dst)[0], ((uint64_t*)msg.id.idiag_dst)[1]}, }}; +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif // __GNUC__ } infos.insert(std::make_pair(inode, info)); return true; diff --git a/core/pipeline/PipelineManager.cpp b/core/pipeline/PipelineManager.cpp index 23fa291329..56c023f57e 100644 --- a/core/pipeline/PipelineManager.cpp +++ b/core/pipeline/PipelineManager.cpp @@ -37,7 +37,10 @@ namespace logtail { void logtail::PipelineManager::UpdatePipelines(ConfigDiff& diff) { #ifndef APSARA_UNIT_TEST_MAIN // 过渡使用 - static bool isInputFileStarted = false, isInputObserverStarted = false, isInputStreamStarted = false; + static bool isInputFileStarted = false, isInputObserverStarted = false; +#if defined(__ENTERPRISE__) && defined(__linux__) && !defined(__ANDROID__) + static bool isInputStreamStarted = false; +#endif bool isInputObserverChanged = false, isInputFileChanged = false, isInputStreamChanged = false; for (const auto& name : diff.mRemoved) { CheckIfInputUpdated(mPipelineNameEntityMap[name]->GetConfig()["inputs"][0], diff --git a/core/processor/ProcessorSPL.cpp b/core/processor/ProcessorSPL.cpp index 67580233b9..b35a21da20 100644 --- a/core/processor/ProcessorSPL.cpp +++ b/core/processor/ProcessorSPL.cpp @@ -17,13 +17,16 @@ #include "processor/ProcessorSPL.h" #include +#ifdef FMT_HEADER_ONLY +#undef FMT_HEADER_ONLY +#endif #include #include #include -#include "common/ParamExtractor.h" #include "common/Flags.h" +#include "common/ParamExtractor.h" #include "logger/Logger.h" #include "monitor/MetricConstants.h" #include "spl/PipelineEventGroupInput.h" diff --git a/core/sdk/Common.cpp b/core/sdk/Common.cpp index 056e8456be..cade8269c0 100644 --- a/core/sdk/Common.cpp +++ b/core/sdk/Common.cpp @@ -198,7 +198,7 @@ namespace sdk { } static unsigned char FromHex(unsigned char x) { - unsigned char y; + unsigned char y = '\0'; if (x >= 'A' && x <= 'Z') y = x - 'A' + 10; else if (x >= 'a' && x <= 'z') diff --git a/core/unittest/CMakeLists.txt b/core/unittest/CMakeLists.txt index 50dae932be..2518b63c88 100644 --- a/core/unittest/CMakeLists.txt +++ b/core/unittest/CMakeLists.txt @@ -22,6 +22,12 @@ if (MSVC) add_definitions(-DNOMINMAX) endif () add_library(${PROJECT_NAME} STATIC ${ALL_SOURCE_FILES}) +if(MSVC) + # For MSVC, use /W4 for a high level of warnings, and treat warnings as errors. + # target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -Werror) +endif() link_jsoncpp(${PROJECT_NAME}) link_yamlcpp(${PROJECT_NAME}) link_boost(${PROJECT_NAME})