]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Use [re]palloc_array() in buffile.c and fd.c
authorMichael Paquier <michael@paquier.xyz>
Fri, 31 Jul 2026 02:48:18 +0000 (11:48 +0900)
committerMichael Paquier <michael@paquier.xyz>
Fri, 31 Jul 2026 02:48:18 +0000 (11:48 +0900)
The code paths patched in this commit fix some of remnants not addressed
by 1b105f9472bd.  We should have more holes in the tree that could
benefit from stronger type safety guarantees.  These hypothetical holes
could be addressed later; this finishes the job in storage/file/ for the
backend code.

Author: Tristan Partin <tristan@partin.io>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/DKBAWPZ2QDOS.10Y3JDUNKFMXX@partin.io

src/backend/storage/file/buffile.c
src/backend/storage/file/fd.c

index 5c59913646bbb0ff2fc3d8f8d44e7f4879820d5a..9d4ea177ddb2ec55bb314f7d64ec83ad4cb29884 100644 (file)
@@ -172,8 +172,7 @@ extendBufFile(BufFile *file)
 
        CurrentResourceOwner = oldowner;
 
-       file->files = (File *) repalloc(file->files,
-                                                                       (file->numFiles + 1) * sizeof(File));
+       file->files = repalloc_array(file->files, File, file->numFiles + 1);
        file->files[file->numFiles] = pfile;
        file->numFiles++;
 }
@@ -915,8 +914,7 @@ BufFileAppend(BufFile *target, BufFile *source)
        if (target->resowner != source->resowner)
                elog(ERROR, "could not append BufFile with non-matching resource owner");
 
-       target->files = (File *)
-               repalloc(target->files, sizeof(File) * newNumFiles);
+       target->files = repalloc_array(target->files, File, newNumFiles);
        for (i = target->numFiles; i < newNumFiles; i++)
                target->files[i] = source->files[i - target->numFiles];
        target->numFiles = newNumFiles;
index 9969bb817166905b81666251b6a0c5c105457e92..190c99744940bc62dfafcfb08c277a10d65b260a 100644 (file)
@@ -976,7 +976,7 @@ count_usable_fds(int max_to_probe, int *usable_fds, int *already_open)
 #endif
 
        size = 1024;
-       fd = (int *) palloc(size * sizeof(int));
+       fd = palloc_array(int, size);
 
 #ifdef HAVE_GETRLIMIT
        getrlimit_status = getrlimit(RLIMIT_NOFILE, &rlim);
@@ -1011,7 +1011,7 @@ count_usable_fds(int max_to_probe, int *usable_fds, int *already_open)
                if (used >= size)
                {
                        size *= 2;
-                       fd = (int *) repalloc(fd, size * sizeof(int));
+                       fd = repalloc_array(fd, int, size);
                }
                fd[used++] = thisfd;