pgsql: Fix incorrect nmembers calculation in test_bitmapset - Mailing list pgsql-committers

From David Rowley
Subject pgsql: Fix incorrect nmembers calculation in test_bitmapset
Date
Msg-id E1wySAR-00000001tL5-13Su@gemulon.postgresql.org
Whole thread
List pgsql-committers
Fix incorrect nmembers calculation in test_bitmapset

This calculation was failing to correctly account for the min_value when
calculating how many random members to add to the Bitmapset.  What the
code was meant to do was add a random number of members between the
minimum and maximum values.  The code failed to account for the minimum
value being non-zero, which could result in too many members being added
to the set, which could reduce the effectiveness of the test.  In reality,
the only caller to this function did pass 0 as the min_value, so there is
no live bug being fixed here.

Fix this so that the Bitmapset is more sparsely populated with members
between the minimum and maximum values.  In passing, swap the order of the
min_value and max_value parameters.  Having the minimum value appear
before the maximum value makes more sense.  Also align the names of both
parameters, and adjust the 'offset' calculation to widen the offset range
by 1 so that the possible range for that random value is -max_value to
max_value.

Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Greg Burd <greg@burd.me>
Discussion: https://postgr.es/m/CAApHDvpfZqdMRmR-6W9UXb+Tanex5wK6PsL=XzYCV4P3pD36Ng@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/53a981ed5bbaa8344da88dfa3550e6cfb6ecf3c9

Modified Files
--------------
.../test_bitmapset/expected/test_bitmapset.out     |  2 +-
.../modules/test_bitmapset/sql/test_bitmapset.sql  |  2 +-
src/test/modules/test_bitmapset/test_bitmapset.c   | 53 ++++++++++++++--------
3 files changed, 37 insertions(+), 20 deletions(-)


pgsql-committers by date:

Previous
From: Nathan Bossart
Date:
Subject: pgsql: Ensure TOAST storage parameters have unsettable defaults.
Next
From: Jeff Davis
Date:
Subject: pgsql: Add C test function for pg_locale.h APIs.