Re: Fix and improve allocation formulas - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Fix and improve allocation formulas
Date
Msg-id aUJnlU38CR_D2XPw@paquier.xyz
Whole thread Raw
In response to Fix and improve allocation formulas  (Bertrand Drouvot <bertranddrouvot.pg@gmail.com>)
Responses Re: Fix and improve allocation formulas
List pgsql-hackers
On Thu, Dec 11, 2025 at 01:27:56PM +0000, Bertrand Drouvot wrote:
> It found two formulas that are technically correct, but using GBT_VARKEY and char
> are the semantically appropriate choices (see 0001 attached).

Bertrand has just reminded me offline that this two have not been
discussed, and that they're a a separate thing.  Looking again at
them.

--- a/contrib/btree_gist/btree_utils_var.c
+++ b/contrib/btree_gist/btree_utils_var.c
@@ -476,7 +476,7 @@ gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
     v->spl_nleft = 0;
     v->spl_nright = 0;

-    sv = palloc(sizeof(bytea *) * (maxoff + 1));
+    sv = palloc(sizeof(GBT_VARKEY *) * (maxoff + 1));

     /* Sort entries */

This one is indeed inconsistent, so this needs to be switched as
proposed.

diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index c9b24df7c05..1cd5fa791c0 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -1007,7 +1007,7 @@ verify_tar_file(verifier_context *context, char *relpath, char *fullpath,
         return;
     }

-    buffer = pg_malloc(READ_CHUNK_SIZE * sizeof(uint8));
+    buffer = pg_malloc(READ_CHUNK_SIZE * sizeof(char));

     /* Perform the reads */
     while ((rc = read(fd, buffer, READ_CHUNK_SIZE)) > 0)

This one reads the same to me, still it seems to me that the intention
is to deal with a byte array.  Doesn't this point to the fact that
using uint8 is more adapted for the astreamer code, following changes
like b28c59a6cd08?  That would be a more invasive change, of course.
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: [Proposal] Adding callback support for custom statistics kinds
Next
From: Amit Langote
Date:
Subject: Re: Segmentation fault on proc exit after dshash_find_or_insert