From 0947148fcc5f1d541e00ae40ea4c4ea5a8867fcc Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sat, 2 Feb 2019 01:58:41 +0000 Subject: [PATCH] Fix compiler warnings Signed-off-by: Yuxuan Shui --- meson.build | 3 ++- src/log.c | 4 ++-- src/string_utils.c | 11 +++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 09c2037..69cfa4f 100644 --- a/meson.build +++ b/meson.build @@ -46,7 +46,8 @@ endif add_global_arguments('-D_GNU_SOURCE', language: 'c') -warns = [ 'all', 'extra', 'no-unused-parameter', 'nonnull', 'shadow', 'implicit-fallthrough' ] +warns = [ 'all', 'extra', 'no-unused-parameter', 'nonnull', 'shadow', + 'implicit-fallthrough', 'no-unknown-warning-option' ] foreach w : warns if cc.has_argument('-W'+w) add_global_arguments('-W'+w, language: 'c') diff --git a/src/log.c b/src/log.c index e3f50bd..2fa4720 100644 --- a/src/log.c +++ b/src/log.c @@ -72,7 +72,7 @@ static attr_const const char *log_level_to_string(enum log_level level) { case LOG_LEVEL_WARN: return "WARN"; case LOG_LEVEL_ERROR: return "ERROR"; case LOG_LEVEL_FATAL: return "FATAL ERROR"; - default: assert(false); + default: return "????"; } } @@ -254,7 +254,7 @@ const char *terminal_colorize_begin(enum log_level level) { case LOG_LEVEL_WARN: return ANSI("33"); case LOG_LEVEL_ERROR: return ANSI("31;1"); case LOG_LEVEL_FATAL: return ANSI("30;103;1"); - default: assert(false); + default: return ""; } } diff --git a/src/string_utils.c b/src/string_utils.c index 6b3a8d2..26b1c5b 100644 --- a/src/string_utils.c +++ b/src/string_utils.c @@ -7,6 +7,15 @@ #include "string_utils.h" #include "utils.h" +#pragma GCC diagnostic push + +// gcc warns about legitimate strncpy in mstrjoin and mstrextend +// strncpy(str, src1, len1) intentional truncates the null byte from src1. +// strncpy(str+len1, src2, len2) uses bound depends on the source argument, +// but str is allocated with len1+len2+1, so this strncpy can't overflow +#pragma GCC diagnostic ignored "-Wstringop-truncation" +#pragma GCC diagnostic ignored "-Wstringop-overflow" + /** * Allocate the space and join two strings. */ @@ -41,6 +50,8 @@ void mstrextend(char **psrc1, const char *src2) { (*psrc1)[len - 1] = '\0'; } +#pragma GCC diagnostic pop + /// Parse a floating point number of form (+|-)?[0-9]*(\.[0-9]*) double strtod_simple(const char *src, const char **end) { double neg = 1;