From ab1d9e98f3c2c4b4954b3b64a226f3bec3fdcdb8 Mon Sep 17 00:00:00 2001 From: Joseph Giovatto Date: Sun, 29 Apr 2018 11:24:35 -0400 Subject: [PATCH] Format and typelimit warnings (#169) * merge with origin 4fc7dbc3 8daa8346 * fixed whitespace diff * added .gitignore * added format warning flags to C_FLAGS added typelimit check to C_FLAGS and CXX_CLAGS * Revert "added format warning flags to C_FLAGS" Apply to branch format_and_typelimt branch This reverts commit bf7467e82ec7b056ad06dc50cc964fcce18be99b. * check for format warnings to top level C_FLAGS added typelimit warnings to top level C_FLAGS and CXX_FLAGS beset effort attempt to remedy warnings removed unused param names in hex_log baseclass methods due to multitude of unused-warnings --- .gitignore | 1 + CMakeLists.txt | 4 ++-- lib/examples/synch_file.c | 2 +- lib/include/srslte/common/log.h | 8 ++++---- lib/include/srslte/common/pdu.h | 2 +- lib/src/common/pdu.cc | 19 +++++++++++++------ lib/src/phy/fec/test/turbocoder_test.c | 2 +- lib/src/phy/phch/test/pbch_file_test.c | 2 +- 8 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..378eac25d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/CMakeLists.txt b/CMakeLists.txt index 290754ee3..d495d54a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,7 +226,7 @@ macro(ADD_CXX_COMPILER_FLAG_IF_AVAILABLE flag have) endmacro(ADD_CXX_COMPILER_FLAG_IF_AVAILABLE) if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${GCC_ARCH} -Wall -Wno-comment -Wno-reorder -Wno-unused-but-set-variable -Wno-unused-variable -Wformat -std=c++03") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${GCC_ARCH} -Wall -Wno-comment -Wno-reorder -Wno-unused-but-set-variable -Wno-unused-variable -Wformat -Wtype-limits -std=c++03") find_package(SSE) if (HAVE_AVX2) @@ -243,7 +243,7 @@ endif(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clan ADD_CXX_COMPILER_FLAG_IF_AVAILABLE("-Werror=incompatible-pointer-types" HAVE_ERROR_INCOMPATIBLE) if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=${GCC_ARCH} -Wall -Wno-comment -Wno-write-strings -Wno-format-extra-args -Winline -Wno-unused-result -Wno-format -std=c99 -D_GNU_SOURCE") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=${GCC_ARCH} -Wall -Wno-comment -Wno-write-strings -Winline -Wno-unused-result -Wformat -Wtype-limits -std=c99 -D_GNU_SOURCE") if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -O0 -DDEBUG_MODE -DBUILD_TYPE_DEBUG") diff --git a/lib/examples/synch_file.c b/lib/examples/synch_file.c index 4d553bd38..c73e8d9dc 100644 --- a/lib/examples/synch_file.c +++ b/lib/examples/synch_file.c @@ -113,7 +113,7 @@ int main(int argc, char **argv) { uint32_t m0, m1; float m0_value, m1_value; uint32_t N_id_2; - uint32_t sss_idx; + int sss_idx; struct timeval tdata[3]; int *exec_time; diff --git a/lib/include/srslte/common/log.h b/lib/include/srslte/common/log.h index b47f79d90..79dbdc088 100644 --- a/lib/include/srslte/common/log.h +++ b/lib/include/srslte/common/log.h @@ -129,13 +129,13 @@ public: virtual void debug(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; // Same with hex dump - virtual void error_hex(const uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + virtual void error_hex(const uint8_t *, int, const char *, ...) __attribute__((format (printf, 4, 5))) {error("error_hex not implemented.\n");} - virtual void warning_hex(const uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + virtual void warning_hex(const uint8_t *, int, const char *, ...) __attribute__((format (printf, 4, 5))) {error("warning_hex not implemented.\n");} - virtual void info_hex(const uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + virtual void info_hex(const uint8_t *, int, const char *, ...) __attribute__((format (printf, 4, 5))) {error("info_hex not implemented.\n");} - virtual void debug_hex(const uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + virtual void debug_hex(const uint8_t *, int, const char *, ...) __attribute__((format (printf, 4, 5))) {error("debug_hex not implemented.\n");} protected: diff --git a/lib/include/srslte/common/pdu.h b/lib/include/srslte/common/pdu.h index cc2bb64f5..e9ee1f0e9 100644 --- a/lib/include/srslte/common/pdu.h +++ b/lib/include/srslte/common/pdu.h @@ -258,7 +258,7 @@ public: private: static const int MAX_CE_PAYLOAD_LEN = 8; uint32_t lcid; - int nof_bytes; + uint32_t nof_bytes; uint8_t* payload; uint8_t w_payload_ce[8]; bool F_bit; diff --git a/lib/src/common/pdu.cc b/lib/src/common/pdu.cc index 95d9dde9b..09fae2774 100644 --- a/lib/src/common/pdu.cc +++ b/lib/src/common/pdu.cc @@ -103,8 +103,10 @@ void sch_pdu::parse_packet(uint8_t *ptr) read_len += subheaders[i].size_plus_header(); } - if (pdu_len-read_len-1 >= 0) { - subheaders[nof_subheaders-1].set_payload_size(pdu_len-read_len-1); + int n_sub = pdu_len-read_len-1; + + if (n_sub >= 0) { + subheaders[nof_subheaders-1].set_payload_size(n_sub); } else { fprintf(stderr,"Reading MAC PDU: negative payload for last subheader\n"); } @@ -584,17 +586,22 @@ int sch_subh::set_sdu(uint32_t lcid_, uint32_t requested_bytes, read_pdu_interfa payload = ((sch_pdu*)parent)->get_current_sdu_ptr(); // Copy data and get final number of bytes written to the MAC PDU - uint32_t sdu_sz = sdu_itf->read_pdu(lcid, payload, requested_bytes); + int sdu_sz = sdu_itf->read_pdu(lcid, payload, requested_bytes); - if (sdu_sz < 0 || sdu_sz > requested_bytes) { + if (sdu_sz < 0) { return -1; } if (sdu_sz == 0) { return 0; } + else { + // Save final number of written bytes + nof_bytes = sdu_sz; - // Save final number of written bytes - nof_bytes = sdu_sz; + if(nof_bytes > requested_bytes) { + return -1; + } + } ((sch_pdu*)parent)->add_sdu(nof_bytes); ((sch_pdu*)parent)->update_space_sdu(nof_bytes); diff --git a/lib/src/phy/fec/test/turbocoder_test.c b/lib/src/phy/fec/test/turbocoder_test.c index 8daeebdb8..f8219a4e2 100644 --- a/lib/src/phy/fec/test/turbocoder_test.c +++ b/lib/src/phy/fec/test/turbocoder_test.c @@ -40,7 +40,7 @@ uint32_t long_cb = 0; void usage(char *prog) { printf("Usage: %s\n", prog); - printf("\t-l long_cb [Default check all]\n", long_cb); + printf("\t-l long_cb [Default %u]\n", long_cb); } void parse_args(int argc, char **argv) { diff --git a/lib/src/phy/phch/test/pbch_file_test.c b/lib/src/phy/phch/test/pbch_file_test.c index 6b79db422..dac516859 100644 --- a/lib/src/phy/phch/test/pbch_file_test.c +++ b/lib/src/phy/phch/test/pbch_file_test.c @@ -208,7 +208,7 @@ int main(int argc, char **argv) { /* Get channel estimates for each port */ srslte_chest_dl_estimate(&chest, fft_buffer, ce, 0); - INFO("Decoding PBCH\n", 0); + INFO("Decoding PBCH\n"); for (int i=0;i