public inbox for [email protected]  
help / color / mirror / Atom feed
From: Jianghua Yang <[email protected]>
To: [email protected]
Subject: BUG: test_bloomfilter error message reports wrong variable and wrong format specifier
Date: Tue, 24 Mar 2026 05:31:55 -0700
Message-ID: <CAAZLFmS2OMiwe65gdm-MKgO=LnKatGMSK6JWxhycGN3TWrhbnw@mail.gmail.com> (raw)

Hi,

  I found a small bug in
src/test/modules/test_bloomfilter/test_bloomfilter.c, line 128.

  The current code:

  int64   nelements = PG_GETARG_INT64(1);
  int     tests = PG_GETARG_INT32(3);

  if (tests <= 0)
      elog(ERROR, "invalid number of tests: %d", tests);

  if (nelements < 0)
      elog(ERROR, "invalid number of elements: %d", tests);

  The second elog has two issues:

  1. It checks nelements but prints tests. For example, with
  nelements = -1 and tests = 1, the error message would be
  "invalid number of elements: 1" — which is misleading when debugging.
  2. nelements is int64, so the format specifier should be
  INT64_FORMAT rather than %d. Using %d for int64 is
  undefined behavior on 32-bit platforms.

  The fix:

  if (nelements < 0)
      elog(ERROR, "invalid number of elements: " INT64_FORMAT, nelements);

  A patch is attached.

  Regards,
  Jianghua Yang


Attachments:

  [application/octet-stream] v1-0001-Fix-wrong-variable-and-format-specifier-in-test_b.patch (1.2K, 3-v1-0001-Fix-wrong-variable-and-format-specifier-in-test_b.patch)
  download | inline diff:
From 2277fdd00175e6158b6863c3c57a5bf73082333c Mon Sep 17 00:00:00 2001
From: Jianghua Yang <[email protected]>
Date: Mon, 23 Mar 2026 18:29:49 -0700
Subject: [PATCH v1] Fix wrong variable and format specifier in
 test_bloomfilter error message

When checking for an invalid number of elements, the error message
incorrectly reported the value of the 'tests' variable instead of
'nelements'.  Additionally, 'nelements' is of type int64, so the
format specifier should be INT64_FORMAT rather than %d.

Author: Jianghua Yang <[email protected]>
---
 src/test/modules/test_bloomfilter/test_bloomfilter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/test/modules/test_bloomfilter/test_bloomfilter.c b/src/test/modules/test_bloomfilter/test_bloomfilter.c
index 4e072183604..df41066138c 100644
--- a/src/test/modules/test_bloomfilter/test_bloomfilter.c
+++ b/src/test/modules/test_bloomfilter/test_bloomfilter.c
@@ -125,7 +125,7 @@ test_bloomfilter(PG_FUNCTION_ARGS)
 		elog(ERROR, "invalid number of tests: %d", tests);
 
 	if (nelements < 0)
-		elog(ERROR, "invalid number of elements: %d", tests);
+		elog(ERROR, "invalid number of elements: " INT64_FORMAT, nelements);
 
 	for (i = 0; i < tests; i++)
 	{
-- 
2.50.1 (Apple Git-155)



view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: BUG: test_bloomfilter error message reports wrong variable and wrong format specifier
  In-Reply-To: <CAAZLFmS2OMiwe65gdm-MKgO=LnKatGMSK6JWxhycGN3TWrhbnw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox