Silent properly GCC format-truncation warnings in jansson

This commit is contained in:
Philippe Teuwen 2019-07-10 22:32:55 +02:00
parent e53ac8b715
commit 73bbb2e9e8
2 changed files with 10 additions and 5 deletions

View file

@ -40,9 +40,6 @@ platform = $(shell uname)
CC= gcc
CFLAGS= -O2 -Wall -Wno-unused-variable -Wno-unused-function
ifneq ($(platform),Darwin)
CFLAGS += -Wno-format-truncation
endif
LDFLAGS= $(SYSLDFLAGS) $(libjansson_la_LDFLAGS)
LIBS= $(SYSLIBS) $(MYLIBS)

View file

@ -111,7 +111,11 @@ static void error_set(json_error_t *error, const lex_t *lex,
if (saved_text && saved_text[0]) {
if (lex->saved_text.length <= 20) {
snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near '%s'", msg_text, saved_text);
int ret = snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near '%s'", msg_text, saved_text);
if (ret < 0) {
jsonp_error_set(error, line, col, pos, code, "%s", "internal snprint error");
return;
}
msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
result = msg_with_context;
}
@ -124,7 +128,11 @@ static void error_set(json_error_t *error, const lex_t *lex,
/* No context for UTF-8 decoding errors */
result = msg_text;
} else {
snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near end of file", msg_text);
int ret = snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near end of file", msg_text);
if (ret < 0) {
jsonp_error_set(error, line, col, pos, code, "%s", "internal snprint error");
return;
}
msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
result = msg_with_context;
}