diff --git a/CMakeLists.txt b/CMakeLists.txt index 65a29ec..b548fa4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.10) set(PACKAGE ivi-logging) PROJECT(${PACKAGE}) @@ -8,7 +8,7 @@ include(GNUInstallDirs) SET( PROJECT_MAJOR_VERSION 1 ) SET( PROJECT_MINOR_VERSION 3 ) -SET( PROJECT_PATCH_LEVEL 0 ) +SET( PROJECT_PATCH_LEVEL 1 ) set(VERSION ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_LEVEL}) set(PACKAGE_VERSION ${VERSION}) @@ -39,13 +39,9 @@ else() set(CONSOLE_OR_NULL NullLogContext) endif() -if (CMAKE_VERSION VERSION_GREATER 3.1) - set(CMAKE_CXX_STANDARD 11) -else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") -endif() +set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wno-variadic-macros -Wno-vla-extension -Wno-gnu-zero-variadic-macro-arguments") +add_definitions(-Wall -pedantic -Wextra -Wno-variadic-macros -Wformat=2 -Wformat-truncation=2) include_directories( include diff --git a/include/ivi-logging-console.h b/include/ivi-logging-console.h index b291d54..54a64f0 100644 --- a/include/ivi-logging-console.h +++ b/include/ivi-logging-console.h @@ -218,7 +218,8 @@ class StreamLogData : public LogData { #pragma GCC diagnostic push // Make sure GCC does not complain about not being able to check the format string since it is no literal string #pragma GCC diagnostic ignored "-Wformat-security" - int size = snprintf(NULL, 0, format, args ...) + 1; // +1 since the snprintf returns the number of characters excluding the null termination +#pragma GCC diagnostic ignored "-Wformat-nonliteral" + int size = snprintf(nullptr, 0, format, args ...) + 1; // +1 since the snprintf returns the number of characters excluding the null termination size_t startOfStringIndex = byteArray.size(); byteArray.resize(byteArray.size() + size); char* p = byteArray.getData() + startOfStringIndex; diff --git a/include/ivi-logging-dlt.h b/include/ivi-logging-dlt.h index abde44e..f40f0a0 100644 --- a/include/ivi-logging-dlt.h +++ b/include/ivi-logging-dlt.h @@ -72,7 +72,7 @@ class DltContextClass : public LogContextBase, private DltContext { // TODO : The piece of code below would be useful if the DLT library didn't always return 0 if (dltCode != 0 ) { - char pidAsHexString[5]; + char pidAsHexString[9]; snprintf(pidAsHexString, sizeof(pidAsHexString), "%X", pid); dltCode = dlt_register_app(pidAsHexString, descriptionWithPID); } @@ -140,6 +140,7 @@ class DltLogData : public LogData, public DltContextData { #pragma GCC diagnostic push // Make sure GCC does not complain about not being able to check the format string since it is no literal string #pragma GCC diagnostic ignored "-Wformat-security" +#pragma GCC diagnostic ignored "-Wformat-nonliteral" snprintf(b, sizeof(b), format, args ...); #pragma GCC diagnostic pop diff --git a/src/backtrace.cpp b/src/backtrace.cpp index 0456b0a..978738c 100644 --- a/src/backtrace.cpp +++ b/src/backtrace.cpp @@ -6,27 +6,27 @@ #include #include #include -#include +#include namespace logging { -std::string getStackTrace(unsigned int max_frames) { +std::string getStackTrace(const unsigned int max_frames) { std::stringstream ss; ss << std::endl; // storage array for stack trace address data - void **addrlist = new void*[max_frames + 1]; + std::vector addrlist(max_frames + 1); // retrieve current stack addresses - int addrlen = backtrace(addrlist, sizeof(addrlist) / sizeof(void*)); + int addrlen = backtrace(addrlist.data(), addrlist.size()); if (addrlen == 0) { ss << ""; } else { // resolve addresses into strings containing "filename(function+address)", // this array must be free()-ed - char** symbollist = backtrace_symbols(addrlist, addrlen); + char** symbollist = backtrace_symbols(addrlist.data(), addrlen); // allocate string which will be filled with the demangled function name size_t funcnamesize = 256; @@ -84,8 +84,6 @@ std::string getStackTrace(unsigned int max_frames) { } - delete [] addrlist; - return ss.str(); } diff --git a/src/ivi-logging.cpp b/src/ivi-logging.cpp index 7477e48..3b89c90 100644 --- a/src/ivi-logging.cpp +++ b/src/ivi-logging.cpp @@ -46,7 +46,7 @@ void setDefaultAPPIDSIfNeeded() { // LOGGING_WARNING_OUTPUT_PREFIX // "Your application should define its ID using the LOG_DEFINE_APP_IDS macro\n"); pid_t pid = getpid(); - char pidAsHex[5]; + char pidAsHex[9]; snprintf(pidAsHex, sizeof(pidAsHex), "%X", pid); // char pidAsDecimal[6]; // snprintf(pidAsDecimal, sizeof(pidAsDecimal), "%i", pid);