From 3ac6ca495869e35d766dcbdfe93b4e0e0b3d3be1 Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Tue, 23 Dec 2025 10:44:27 +0800 Subject: [PATCH v3] Refactor BufFile buffer fields to eliminate odd type casts Use int64 for BufFile buffer position and length fields, and adjust related local variables accordingly. This avoids repeated and confusing casts between int and wider types when computing buffer offsets and write sizes. No functional change intended. Author: Chao Li Discussion: https://postgr.es/m/aUStrqoOCDRFAq1M@paquier.xyz --- src/backend/storage/file/buffile.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c index 85b316d879d..d42b630d8cc 100644 --- a/src/backend/storage/file/buffile.c +++ b/src/backend/storage/file/buffile.c @@ -93,8 +93,8 @@ struct BufFile */ int curFile; /* file index (0..n) part of current pos */ pgoff_t curOffset; /* offset part of current pos */ - int pos; /* next read/write position in buffer */ - int nbytes; /* total # of valid bytes in buffer */ + int64 pos; /* next read/write position in buffer */ + int64 nbytes; /* total # of valid bytes in buffer */ /* * XXX Should ideally use PGIOAlignedBlock, but might need a way to avoid @@ -493,8 +493,8 @@ BufFileLoadBuffer(BufFile *file) static void BufFileDumpBuffer(BufFile *file) { - int wpos = 0; - int bytestowrite; + int64 wpos = 0; + int64 bytestowrite; File thisfile; /* @@ -503,7 +503,7 @@ BufFileDumpBuffer(BufFile *file) */ while (wpos < file->nbytes) { - pgoff_t availbytes; + int64 availbytes; instr_time io_start; instr_time io_time; @@ -524,8 +524,8 @@ BufFileDumpBuffer(BufFile *file) bytestowrite = file->nbytes - wpos; availbytes = MAX_PHYSICAL_FILESIZE - file->curOffset; - if ((pgoff_t) bytestowrite > availbytes) - bytestowrite = (int) availbytes; + if (bytestowrite > availbytes) + bytestowrite = availbytes; thisfile = file->files[file->curFile]; @@ -983,10 +983,10 @@ BufFileTruncateFileSet(BufFile *file, int fileno, pgoff_t offset) { /* No need to reset the current pos if the new pos is greater. */ if (newOffset <= file->curOffset + file->pos) - file->pos = (int) (newOffset - file->curOffset); + file->pos = newOffset - file->curOffset; /* Adjust the nbytes for the current buffer. */ - file->nbytes = (int) (newOffset - file->curOffset); + file->nbytes = newOffset - file->curOffset; } else if (newFile == file->curFile && newOffset < file->curOffset) -- 2.39.5 (Apple Git-154)