From: Michael Paquier Date: Fri, 31 Jul 2026 02:48:18 +0000 (+0900) Subject: Use [re]palloc_array() in buffile.c and fd.c X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d64c805dea27d189904394ece7576762bece278c;p=thirdparty%2Fpostgresql.git Use [re]palloc_array() in buffile.c and fd.c 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 Reviewed-by: Daniel Gustafsson Reviewed-by: Sami Imseih Discussion: https://postgr.es/m/DKBAWPZ2QDOS.10Y3JDUNKFMXX@partin.io --- diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c index 5c59913646b..9d4ea177ddb 100644 --- a/src/backend/storage/file/buffile.c +++ b/src/backend/storage/file/buffile.c @@ -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; diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 9969bb81716..190c9974494 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -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;