I was reading some buffile.c code, and I noticed some hand-rolled versions of repalloc_array() (minus the multiplication check). Since we already have one usage of repalloc_array() in buffile.c for BufFile::files, I figured it would probably be alright if we used it in the other two locations as well.
-- Tristan Partin PostgreSQL Contributors Team AWS (https://aws.amazon.com)
diff --git i/src/backend/storage/file/buffile.c w/src/backend/storage/file/buffile.c index 5c59913646b..9d4ea177ddb 100644 --- i/src/backend/storage/file/buffile.c +++ w/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;
