Re: Fix possible bogus array out of bonds (src/backend/access/brin/brin_minmax_multi.c) - Mailing list pgsql-hackers

From David Rowley
Subject Re: Fix possible bogus array out of bonds (src/backend/access/brin/brin_minmax_multi.c)
Date
Msg-id CAApHDvqT=v15PRz0YXFJzczi6NirzR_vrk-ekCz9VEeTP84Fmw@mail.gmail.com
Whole thread Raw
In response to Fix possible bogus array out of bonds (src/backend/access/brin/brin_minmax_multi.c)  (Ranier Vilela <ranier.vf@gmail.com>)
List pgsql-hackers
On Mon, 5 Sept 2022 at 22:15, David Rowley <dgrowleyml@gmail.com> wrote:
> On Sat, 3 Sept 2022 at 00:37, Ranier Vilela <ranier.vf@gmail.com> wrote:
> > 6. Avoid overhead when using unnecessary StringInfoData to convert Datum a to Text b.
>
> I've ripped out #4 and #6 for now. I think we should do #6 in master
> only, probably as part of a wider cleanup of StringInfo misusages.

I've attached a patch which does various other string operation cleanups.

* This changes cstring_to_text() to use cstring_to_text_with_len when
we're working with a StringInfo and can just access the .len field.
* Uses appendStringInfoString instead of appendStringInfo when there
is special formatting.
* Uses pstrdup(str) instead of psprintf("%s", str).  In many cases
this will save a bit of memory
* Uses appendPQExpBufferChar instead of appendPQExpBufferStr() when
appending a 1 byte string.
* Uses appendStringInfoChar() instead of appendStringInfo() when no
formatting and string is 1 byte.
* Uses appendStringInfoChar() instead of appendStringInfoString() when
string is 1 byte.
* Uses appendPQExpBuffer(b , ...) instead of appendPQExpBufferStr(b, "%s" ...)

I'm aware there are a few other places that we could use
cstring_to_text_with_len() instead of cstring_to_text(). For example,
using the return value of snprintf() to obtain the length. I just
didn't do that because we need to take care to check the return value
isn't -1.

My grep patterns didn't account for these function calls spanning
multiple lines, so I may have missed a few.

David

Attachment

pgsql-hackers by date:

Previous
From: Kazutaka Onishi
Date:
Subject: Re: Asynchronous execution support for Custom Scan
Next
From: David Rowley
Date:
Subject: Re: Reducing the chunk header sizes on all memory context types