From cfaacbff4d841a90f310961032a9d526ef872d27 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Sun, 31 Oct 2021 09:40:14 +0200 Subject: [PATCH] Enable -Werror and fix all warnings --- CMakeLists.txt | 4 +++- src/rtpstream.cpp | 16 ++++++++++------ src/screen.cpp | 19 ++++++++----------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f99792ab..189cbab1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_CXX_EXTENSIONS False) # specify the C++ standard on older CMake (<3.8) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -pedantic -Wno-error=format-truncation -Wno-error=deprecated-declarations") +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -pedantic -Wno-multichar -Wno-deprecated-copy") +endif() # Include binary dir first, where we add generated config.h and # version.h. If nothing is found there (release tar) use the version.h diff --git a/src/rtpstream.cpp b/src/rtpstream.cpp index fbb02eb2..64a4b8d2 100644 --- a/src/rtpstream.cpp +++ b/src/rtpstream.cpp @@ -44,6 +44,10 @@ static void debugprint(const char* format, ...) #endif } +static unsigned long tid_self() { + return reinterpret_cast(pthread_self()); +} + struct free_delete { void operator()(void* x) { free(x); } }; @@ -202,7 +206,7 @@ void printAudioHexUS(char const* note, unsigned char const* string, unsigned int rtpcheck_debug) { pthread_mutex_lock(&debugamutex); - fprintf(debugafile, "TID: %lu %s %u 0x%llx %d [", pthread_self(), note, size, extrainfo, moreinfo); + fprintf(debugafile, "TID: %lu %s %u 0x%llx %d [", tid_self(), note, size, extrainfo, moreinfo); for (unsigned int i = 0; i < size; i++) { fprintf(debugafile, "%02X", 0x000000FF & string[i]); @@ -220,7 +224,7 @@ void printVideoHexUS(char const* note, unsigned char const* string, unsigned int rtpcheck_debug) { pthread_mutex_lock(&debugvmutex); - fprintf(debugvfile, "TID: %lu %s %u 0x%llx %d [", pthread_self(), note, size, extrainfo, moreinfo); + fprintf(debugvfile, "TID: %lu %s %u 0x%llx %d [", tid_self(), note, size, extrainfo, moreinfo); for (unsigned int i = 0; i < size; i++) { fprintf(debugvfile, "%02X", 0x000000FF & string[i]); @@ -238,7 +242,7 @@ void printAudioHex(char const* note, char const* string, unsigned int size, unsi rtpcheck_debug) { pthread_mutex_lock(&debugamutex); - fprintf(debugafile, "TID: %lu %s %u 0x%llx %d [", pthread_self(), note, size, extrainfo, moreinfo); + fprintf(debugafile, "TID: %lu %s %u 0x%llx %d [", tid_self(), note, size, extrainfo, moreinfo); for (unsigned int i = 0; i < size; i++) { fprintf(debugafile, "%02X", 0x000000FF & string[i]); @@ -255,7 +259,7 @@ void printAudioVector(char const* note, std::vector const &v) rtpcheck_debug) { pthread_mutex_lock(&debugamutex); - fprintf(debugafile, "TID: %lu %s\n", pthread_self(), note); + fprintf(debugafile, "TID: %lu %s\n", tid_self(), note); for (unsigned int i = 0; i < v.size(); i++) { fprintf(debugafile, "%lu\n", v[i]); @@ -272,7 +276,7 @@ void printVideoHex(char const* note, char const* string, unsigned int size, unsi rtpcheck_debug) { pthread_mutex_lock(&debugvmutex); - fprintf(debugvfile, "TID: %lu %s %u 0x%llx %d [", pthread_self(), note, size, extrainfo, moreinfo); + fprintf(debugvfile, "TID: %lu %s %u 0x%llx %d [", tid_self(), note, size, extrainfo, moreinfo); for (unsigned int i = 0; i < size; i++) { fprintf(debugvfile, "%02X", 0x000000FF & string[i]); @@ -289,7 +293,7 @@ void printVideoVector(char const* note, std::vector const &v) rtpcheck_debug) { pthread_mutex_lock(&debugvmutex); - fprintf(debugvfile, "TID: %lu %s\n", pthread_self(), note); + fprintf(debugvfile, "TID: %lu %s\n", tid_self(), note); for (unsigned int i = 0; i < v.size(); i++) { fprintf(debugvfile, "%lu\n", v[i]); diff --git a/src/screen.cpp b/src/screen.cpp index 16bcd36b..43cc9581 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -178,11 +178,7 @@ void ScreenPrinter::get_lines() while (isspace(*errstart)) { errstart++; } - if (strlen(errstart) > 60) { - snprintf(buf, bufsiz, "Last Error: %.60s...", errstart); - } else { - snprintf(buf, bufsiz, "Last Error: %s", errstart); - } + snprintf(buf, bufsiz, "Last Error: %.60s...", errstart); lines.push_back(buf); } @@ -264,9 +260,10 @@ bool do_hide = true; void ScreenPrinter::draw_scenario_screen() { - unsigned const bufsiz = 80; + unsigned const bufsiz = 100; char buf[bufsiz]; char left_buf[40]; + char left_buf_long[60]; char right_buf[bufsiz]; extern int pollnfds; @@ -306,20 +303,20 @@ void ScreenPrinter::draw_scenario_screen() /* 1st line */ unsigned long ms_since_last_tick = clock_tick - last_report_time; if (total_calls < stop_after) { - snprintf(left_buf, 40, "%llu new calls during %lu.%03lu s period", + snprintf(left_buf_long, 60, "%llu new calls during %lu.%03lu s period", display_scenario->stats->GetStat( CStat::CPT_PD_IncomingCallCreated) + display_scenario->stats->GetStat( CStat::CPT_PD_OutgoingCallCreated), ms_since_last_tick / 1000, ms_since_last_tick % 1000); } else { - snprintf(left_buf, 40, + snprintf(left_buf_long, 60, "Call limit %lu hit, %0.1f s period ", stop_after, (double)ms_since_last_tick / 100.0); } snprintf(right_buf, 40, "%lu ms scheduler resolution", ms_since_last_tick / std::max(scheduling_loops, 1ul)); - snprintf(buf, bufsiz, " %-38.38s %-37.37s", left_buf, right_buf); + snprintf(buf, bufsiz, " %-38.38s %-37.37s", left_buf_long, right_buf); lines.push_back(buf); /* 2nd line */ @@ -641,8 +638,8 @@ void ScreenPrinter::draw_scenario_screen() ERROR("Scenario command %d not implemented in display", curmsg->M_type); } - char buf_with_index[80] = {0}; - snprintf(buf_with_index, 80, "%-2lu:%s", index, buf); + char buf_with_index[121]; + snprintf(buf_with_index, 121, "%-2lu:%s", index, buf); lines.push_back(buf_with_index); if (curmsg->crlf) { lines.push_back("");