diff --git a/configure.ac b/configure.ac index ca8b2538d..b8b063fb2 100644 --- a/configure.ac +++ b/configure.ac @@ -223,8 +223,8 @@ AC_PROG_LN_S # -Wall CC, CXX # -PROSPECTIVE_CFLAGS="-Wall -std=c99 -pedantic-errors" -PROSPECTIVE_CXXFLAGS="-Wall" +PROSPECTIVE_CFLAGS="-Wall -Wextra -Wshadow -Werror -std=c99 -pedantic-errors" +PROSPECTIVE_CXXFLAGS="-Wall -Wextra -Wshadow -Werror" AC_CACHE_CHECK([whether $CC is Clang], [nl_cv_clang], diff --git a/examples/Makefile-cc2538 b/examples/Makefile-cc2538 index b0d78b540..4206c9d5c 100644 --- a/examples/Makefile-cc2538 +++ b/examples/Makefile-cc2538 @@ -54,9 +54,6 @@ COMMONCFLAGS := \ -ffunction-sections \ -Os \ -g \ - -Wall \ - -Wextra \ - -Werror \ $(NULL) CPPFLAGS += \ diff --git a/examples/Makefile-posix b/examples/Makefile-posix index 42eac0f13..fc1fc5fe5 100644 --- a/examples/Makefile-posix +++ b/examples/Makefile-posix @@ -44,9 +44,6 @@ BuildJobs ?= 99 COMMONCFLAGS := \ -O1 \ -g \ - -Wall \ - -Wextra \ - -Werror \ $(NULL) CPPFLAGS += \ diff --git a/examples/platforms/posix/logging.c b/examples/platforms/posix/logging.c index 05e3a02e6..912fb7754 100644 --- a/examples/platforms/posix/logging.c +++ b/examples/platforms/posix/logging.c @@ -41,21 +41,21 @@ // Macro to append content to end of the log string. #define LOG_PRINTF(...) \ - charsWritten = snprintf(&logString[index], sizeof(logString) - index , __VA_ARGS__); \ - VerifyOrExit(charsWritten >= 0, logString[index] = 0); \ - index += (unsigned int)charsWritten; \ - VerifyOrExit(index < sizeof(logString), logString[sizeof(logString) -1 ] = 0) + charsWritten = snprintf(&logString[offset], sizeof(logString) - offset , __VA_ARGS__); \ + VerifyOrExit(charsWritten >= 0, logString[offset] = 0); \ + offset += (unsigned int)charsWritten; \ + VerifyOrExit(offset < sizeof(logString), logString[sizeof(logString) -1 ] = 0) void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) { struct timeval tv; char timeString[40]; char logString[512]; - unsigned int index; + unsigned int offset; int charsWritten; va_list args; - index = 0; + offset = 0; gettimeofday(&tv, NULL); strftime(timeString, sizeof(timeString), "%Y-%m-%d %H:%M:%S", localtime(&tv.tv_sec)); @@ -129,10 +129,10 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat } va_start(args, aFormat); - charsWritten = vsnprintf(&logString[index], sizeof(logString) - index, aFormat, args); + charsWritten = vsnprintf(&logString[offset], sizeof(logString) - offset, aFormat, args); va_end(args); - VerifyOrExit(charsWritten >= 0, logString[index] = 0); + VerifyOrExit(charsWritten >= 0, logString[offset] = 0); exit: fprintf(stderr, "%s\r", logString); diff --git a/tests/unit/test_diag.cpp b/tests/unit/test_diag.cpp index 488c773af..88fd8b367 100644 --- a/tests/unit/test_diag.cpp +++ b/tests/unit/test_diag.cpp @@ -143,7 +143,7 @@ void TestDiag() // initialize platform layer int argc = 2; - char *argv[2] = {(char *)"test_diag", (char *)"1"}; + char *argv[8] = {(char *)"test_diag", (char *)"1"}; PlatformInit(argc, argv); // initialize diagnostics module @@ -156,12 +156,11 @@ void TestDiag() { char string[50]; int length = strlen(tests[i].command); - char *cmd; - char *argv[8]; - int argc = 0; char *output = NULL; + argc = 0; + memcpy(string, tests[i].command, length + 1); for (cmd = string + 1; (cmd < string + length) && (cmd != NULL); ++cmd) diff --git a/tests/unit/test_lowpan.cpp b/tests/unit/test_lowpan.cpp index 7a03fcccd..f2b392983 100644 --- a/tests/unit/test_lowpan.cpp +++ b/tests/unit/test_lowpan.cpp @@ -145,12 +145,12 @@ void TestLowpanIphc(void) "6lo: Lowpan::Decompress failed"); // ===> Test Lowpan::Compress - int resultLength = sMockLowpan.Compress(*message, macSource, macDest, - result); + int compressBytes = sMockLowpan.Compress(*message, macSource, macDest, + result); printf("Compressed OpenThread:\n"); - otTestPrintHex(result, resultLength); + otTestPrintHex(result, compressBytes); - VerifyOrQuit(memcmp(frame.GetPayload(), result, resultLength) == 0, + VerifyOrQuit(memcmp(frame.GetPayload(), result, compressBytes) == 0, "6lo: Lowpan::Compress failed"); SuccessOrQuit(Message::Free(*message), "6lo: Message:Free failed");