From 73bbb2e9e8d16df071fc923a1d311fbe35ca6f73 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 10 Jul 2019 22:32:55 +0200 Subject: [PATCH] Silent properly GCC format-truncation warnings in jansson --- client/jansson/Makefile | 3 --- client/jansson/load.c | 12 ++++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/client/jansson/Makefile b/client/jansson/Makefile index 1a60613d0..e06ffbc76 100644 --- a/client/jansson/Makefile +++ b/client/jansson/Makefile @@ -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) diff --git a/client/jansson/load.c b/client/jansson/load.c index 43e035cb2..4e05dc87b 100644 --- a/client/jansson/load.c +++ b/client/jansson/load.c @@ -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; }