pgsql: Replace static buf with a stack-allocated one in 'seg' extension

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Replace static buf with a stack-allocated one in 'seg' extension
Date: 2024-07-30 19:24:48
Message-ID: E1sYsSm-001vmA-1f@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Replace static buf with a stack-allocated one in 'seg' extension

The buffer is used only locally within the function. Also, the
initialization to '0' characters was unnecessary, the initial content
were always overwritten with sprintf(). I don't understand why it was
done that way, but it's been like that since forever.

In the passing, change from sprintf() to snprintf(). The buffer was
long enough so sprintf() was fine, but this makes it more obvious that
there's no risk of a buffer overflow.

Reviewed-by: Robert Haas
Discussion: https://www.postgresql.org/message-id/7f86e06a-98c5-4ce3-8ec9-3885c8de0358@iki.fi

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/01e51ed78070703c7e078f1519ad59af38e2888a

Modified Files
--------------
contrib/seg/segparse.y | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Jeff Davis 2024-07-30 23:51:38 pgsql: Relax check for return value from second call of pg_strnxfrm().
Previous Message Heikki Linnakangas 2024-07-30 12:20:38 pgsql: Remove leftover function declaration