postgres.git / summary / log / commit / refs

commit    24dc4afebd5a82f30aed6bd18d48ff42ef787410
Author:   Daniel Gustafsson <dgustafsson@postgresql.org>
Date:     Thu Feb 29 11:19:52 2024 +0000
First released in: 17.0, 12.19, 13.15, 14.12, 15.7, 16.3

    Fix integer underflow in shared memory debugging
    
    dsa_dump would print a large negative number instead of zero for
    segment bin 0.  Fix by explicitly checking for underflow and add
    special case for bin 0. Backpatch to all supported versions.
    
    Author: Ian Ilyasov <ianilyasov@outlook.com>
    Reviewed-by: Robert Haas <robertmhaas@gmail.com>
    Discussion: https://postgr.es/m/GV1P251MB1004E0D09D117D3CECF9256ECD502@GV1P251MB1004.EURP251.PROD.OUTLOOK.COM
    Backpatch-through: v12


src/backend/utils/mmgr/dsa.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/backend/utils/mmgr/dsa.c b/src/backend/utils/mmgr/dsa.c index 35e166dd3db..564995db79e 100644 --- a/src/backend/utils/mmgr/dsa.c +++ b/src/backend/utils/mmgr/dsa.c @@ -1093,9 +1093,13 @@ dsa_dump(dsa_area *area) { dsa_segment_index segment_index; - fprintf(stderr, - " segment bin %zu (at least %d contiguous pages free):\n", - i, 1 << (i - 1)); + if (i == 0) + fprintf(stderr, + " segment bin %zu (no contiguous free pages):\n", i); + else + fprintf(stderr, + " segment bin %zu (at least %d contiguous pages free):\n", + i, 1 << (i - 1)); segment_index = area->control->segment_bins[i]; while (segment_index != DSA_SEGMENT_INDEX_NONE) { [parent: c0b4dad38e84]