Fix compiler warnings

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-02-02 01:58:41 +00:00
parent 465a968ddd
commit 0947148fcc
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
3 changed files with 15 additions and 3 deletions

View File

@ -46,7 +46,8 @@ endif
add_global_arguments('-D_GNU_SOURCE', language: 'c') 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 foreach w : warns
if cc.has_argument('-W'+w) if cc.has_argument('-W'+w)
add_global_arguments('-W'+w, language: 'c') add_global_arguments('-W'+w, language: 'c')

View File

@ -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_WARN: return "WARN";
case LOG_LEVEL_ERROR: return "ERROR"; case LOG_LEVEL_ERROR: return "ERROR";
case LOG_LEVEL_FATAL: return "FATAL 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_WARN: return ANSI("33");
case LOG_LEVEL_ERROR: return ANSI("31;1"); case LOG_LEVEL_ERROR: return ANSI("31;1");
case LOG_LEVEL_FATAL: return ANSI("30;103;1"); case LOG_LEVEL_FATAL: return ANSI("30;103;1");
default: assert(false); default: return "";
} }
} }

View File

@ -7,6 +7,15 @@
#include "string_utils.h" #include "string_utils.h"
#include "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. * Allocate the space and join two strings.
*/ */
@ -41,6 +50,8 @@ void mstrextend(char **psrc1, const char *src2) {
(*psrc1)[len - 1] = '\0'; (*psrc1)[len - 1] = '\0';
} }
#pragma GCC diagnostic pop
/// Parse a floating point number of form (+|-)?[0-9]*(\.[0-9]*) /// Parse a floating point number of form (+|-)?[0-9]*(\.[0-9]*)
double strtod_simple(const char *src, const char **end) { double strtod_simple(const char *src, const char **end) {
double neg = 1; double neg = 1;