1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Use [re]palloc_array() in buffile.c and fd.c

The code paths patched in this commit fix some of remnants not addressed
by 1b105f9472.  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
This commit is contained in:
Michael Paquier
2026-07-31 11:48:18 +09:00
parent d6eac69174
commit d64c805dea
2 changed files with 4 additions and 6 deletions

View 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;

View 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;