From dd87d59f475dae07e3acea8df3852dc9a6a12fce Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 17 Mar 2014 17:50:57 +0100 Subject: Compiler option cleanup and -Wextra fixes --- mmss-protocol/CMakeLists.txt | 2 +- mmss/CMakeLists.txt | 3 ++- mmss/config.l | 4 +++- mmss/context.cpp | 4 ++-- mmss/event.cpp | 4 ++-- mmss/gmrf.cpp | 20 ++++++++++---------- mmss/types.hpp | 8 ++++---- 7 files changed, 24 insertions(+), 21 deletions(-) diff --git a/mmss-protocol/CMakeLists.txt b/mmss-protocol/CMakeLists.txt index dd670f3..69caf64 100644 --- a/mmss-protocol/CMakeLists.txt +++ b/mmss-protocol/CMakeLists.txt @@ -3,4 +3,4 @@ include_directories(${GMRF_SOURCE_DIR}/include) add_library(mmss_protocol STATIC mmss_protocol.c ) -set_target_properties(mmss_protocol PROPERTIES POSITION_INDEPENDENT_CODE 1) +set_target_properties(mmss_protocol PROPERTIES COMPILE_FLAGS "-std=c99 -Wall" POSITION_INDEPENDENT_CODE 1) diff --git a/mmss/CMakeLists.txt b/mmss/CMakeLists.txt index 7e942f5..c71b9b1 100644 --- a/mmss/CMakeLists.txt +++ b/mmss/CMakeLists.txt @@ -1,4 +1,5 @@ include_directories(${GMRF_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +set_directory_properties(PROPERTIES COMPILE_DEFINITIONS _GNU_SOURCE) FLEX_TARGET(mmss_config_lex config.l ${CMAKE_CURRENT_BINARY_DIR}/config.ll.cpp) BISON_TARGET(mmss_config_parse config.y ${CMAKE_CURRENT_BINARY_DIR}/config.yy.cpp) @@ -16,4 +17,4 @@ add_executable(mmss ${BISON_mmss_config_parse_OUTPUTS} ) target_link_libraries(mmss dl) -set_target_properties(mmss PROPERTIES COMPILE_FLAGS -std=c++11) +set_target_properties(mmss PROPERTIES COMPILE_FLAGS "-std=c++11 -Wall") diff --git a/mmss/config.l b/mmss/config.l index 10c1a9d..d81ba20 100644 --- a/mmss/config.l +++ b/mmss/config.l @@ -44,6 +44,8 @@ %{ /* register is deprecated in C++11 */ #define register + + #pragma GCC diagnostic ignored "-Wunused-parameter" %} %s NEEDSPACE @@ -121,7 +123,7 @@ days { TOKEN(TOK_DAYS); } \\. { yylloc->last_column+=2; yymore(); } \\\n { yylloc->last_line++; yylloc->last_column = 0; yymore(); } \" { - int i, esc = 0; + size_t i, esc = 0; for (i = 0; i < yyleng; i++) { if (yytext[i] == '\\') { diff --git a/mmss/context.cpp b/mmss/context.cpp index a6a24e7..b4d001d 100644 --- a/mmss/context.cpp +++ b/mmss/context.cpp @@ -42,7 +42,7 @@ static inline int snprintf_safe(char *buffer, size_t size, const char *format, . int ret = std::vsnprintf(buffer, size, format, ap); va_end(ap); - return ret < 0 ? 0 : ret > size ? size : ret; + return ret < 0 ? 0 : (size_t)ret > size ? size : ret; } static inline const char* get_log_prefix(int log_level) { @@ -99,7 +99,7 @@ void context_t::run(int argc, char *argv[]) { std::exit(1); while (true) { - if (now() > 10000000) + if (now() > 5*3600*1000) break; int timeout = event_queue.timeout(); diff --git a/mmss/event.cpp b/mmss/event.cpp index 3e32605..94aefac 100644 --- a/mmss/event.cpp +++ b/mmss/event.cpp @@ -31,7 +31,7 @@ namespace MMSS { -void packet_t::handle(context_t *mmss) { +void packet_t::handle(context_t *mmss UNUSED) { auto iface = dest.lock(); if (!iface) return; @@ -39,7 +39,7 @@ void packet_t::handle(context_t *mmss) { iface->get_node()->handle_packet(iface, &source_addr, data.get(), len); } -void scheduled_t::handle(context_t *mmss) { +void scheduled_t::handle(context_t *mmss UNUSED) { auto node_ptr = node.lock(); if (!node_ptr) return; diff --git a/mmss/gmrf.cpp b/mmss/gmrf.cpp index 9db3c43..c7b2fbc 100644 --- a/mmss/gmrf.cpp +++ b/mmss/gmrf.cpp @@ -34,25 +34,25 @@ using namespace MMSS; extern "C" { -gmrf_addr_t gmrf_iface_get_addr(gmrf_t *gmrf, gmrf_iface_t *iface) { +gmrf_addr_t gmrf_iface_get_addr(gmrf_t *gmrf UNUSED, gmrf_iface_t *iface) { return *(static_cast(iface)->get_address()); } -const char* gmrf_iface_get_name(gmrf_t *gmrf, gmrf_iface_t *iface) { +const char* gmrf_iface_get_name(gmrf_t *gmrf UNUSED, gmrf_iface_t *iface) { return static_cast(iface)->get_name().c_str(); } -size_t gmrf_iface_get_mtu(gmrf_t *gmrf, gmrf_iface_t *iface) { +size_t gmrf_iface_get_mtu(gmrf_t *gmrf UNUSED, gmrf_iface_t *iface) { return static_cast(iface)->get_network()->get_mtu(); } -bool gmrf_iface_send(gmrf_t *gmrf, gmrf_iface_t *iface, const void *data, size_t len, const gmrf_addr_t *dest) { +bool gmrf_iface_send(gmrf_t *gmrf UNUSED, gmrf_iface_t *iface, const void *data, size_t len, const gmrf_addr_t *dest) { static_cast(iface)->send(data, len, dest); return true; } -bool gmrf_iface_send_bc(gmrf_t *gmrf, gmrf_iface_t *iface, const void *data, size_t len) { +bool gmrf_iface_send_bc(gmrf_t *gmrf UNUSED, gmrf_iface_t *iface, const void *data, size_t len) { static_cast(iface)->send_bc(data, len); return true; @@ -86,19 +86,19 @@ void gmrf_logf(gmrf_t *gmrf, int priority, const char *format, ...) { va_end(ap); } -void gmrf_debug_init(gmrf_t *gmrf, const uint8_t *node_id, size_t len) { +void gmrf_debug_init(gmrf_t *gmrf UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED) { } -void gmrf_debug_neigh(gmrf_t *gmrf, gmrf_iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost) { +void gmrf_debug_neigh(gmrf_t *gmrf UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, float rxcost UNUSED, float txcost UNUSED) { } -void gmrf_debug_neigh_lost(gmrf_t *gmrf, gmrf_iface_t *iface, const gmrf_addr_t *addr) { +void gmrf_debug_neigh_lost(gmrf_t *gmrf UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED) { } -void gmrf_debug_route(gmrf_t *gmrf, const uint8_t *node_id, size_t len, gmrf_iface_t *iface, const gmrf_addr_t *addr, int metric) { +void gmrf_debug_route(gmrf_t *gmrf UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, int metric UNUSED) { } -void gmrf_debug_route_lost(gmrf_t *gmrf, const uint8_t *node_id, size_t len) { +void gmrf_debug_route_lost(gmrf_t *gmrf UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED) { } } diff --git a/mmss/types.hpp b/mmss/types.hpp index 668e2c2..bf95437 100644 --- a/mmss/types.hpp +++ b/mmss/types.hpp @@ -26,16 +26,16 @@ #pragma once -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - extern "C" { #include } + +#define UNUSED __attribute__((unused)) + + struct gmrf {}; struct gmrf_iface {}; -- cgit v1.2.3