On Tue, Apr 3, 2018 at 8:39 AM, Peter Eisentraut <[email protected]> wrote: > There is a compiler warning in the tests, with gcc-7: > > test_bloomfilter.c: In function 'test_bloomfilter': > test_bloomfilter.c:40:38: error: '__builtin_snprintf' output may be > truncated before the last format character [-Werror=format-truncation=] > snprintf(element, sizeof(element), "i" INT64_FORMAT, i); > ^ > > This can be fixed by allocating one more byte for the possible sign, or > doing the whole thing in unsigned.
I don't want to do the whole thing in unsigned, because this ties back fairly directly to an int8 argument from the test_bloomfilter() SQL function interface. I proposed the attached, which makes the buffer one byte larger, per your suggestion. Thanks -- Peter Geoghegan
From 4464e134eae415c47c437393073411c26d64bd4a Mon Sep 17 00:00:00 2001 From: Peter Geoghegan <[email protected]> Date: Tue, 3 Apr 2018 10:25:41 -0700 Subject: [PATCH] Fix GCC 7 snprintf() compiler warning. Make buffer 1 byte larger to fit a sign. It's actually impossible for there to be a sign in practice, but this is still required to keep GCC 7 happy. Cleanup from commit 51bc271790eb234a1ba4d14d3e6530f70de92ab5. Based on a suggestion from Peter Eisentraut. Author: Peter Geoghegan Reported-By: Peter Eisentraut Discussion: https://postgr.es/m/[email protected] --- src/test/modules/test_bloomfilter/test_bloomfilter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/modules/test_bloomfilter/test_bloomfilter.c b/src/test/modules/test_bloomfilter/test_bloomfilter.c index 1691b0f..358afbe 100644 --- a/src/test/modules/test_bloomfilter/test_bloomfilter.c +++ b/src/test/modules/test_bloomfilter/test_bloomfilter.c @@ -18,8 +18,8 @@ PG_MODULE_MAGIC; -/* Must fit decimal representation of PG_INT64_MAX + 2 bytes: */ -#define MAX_ELEMENT_BYTES 20 +/* Fits decimal representation of PG_INT64_MIN + 2 bytes: */ +#define MAX_ELEMENT_BYTES 21 /* False positive rate WARNING threshold (1%): */ #define FPOSITIVE_THRESHOLD 0.01 -- 2.7.4
