Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Fix compiler warnings #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.10)

set(PACKAGE ivi-logging)
PROJECT(${PACKAGE})
Expand All @@ -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})
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion include/ivi-logging-console.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion include/ivi-logging-dlt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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

Expand Down
12 changes: 5 additions & 7 deletions src/backtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
#include <execinfo.h>
#include <cxxabi.h>
#include <sstream>
#include <sstream>
#include <vector>

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<void*> 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 << "<empty, possibly corrupt>";
} 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;
Expand Down Expand Up @@ -84,8 +84,6 @@ std::string getStackTrace(unsigned int max_frames) {

}

delete [] addrlist;

return ss.str();

}
Expand Down
2 changes: 1 addition & 1 deletion src/ivi-logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down