Skip to content

Commit aa55183

Browse files
committed
Use 64 bit type for BufFileSize().
BufFileSize() can't use off_t, because it's only 32 bits wide on some systems. BufFile objects can have many 1GB segments so the total size can exceed 2^31. The only known client of the function is parallel CREATE INDEX, which was reported to fail when building large indexes on Windows. Though this is technically an ABI break on platforms with a 32 bit off_t and we might normally avoid back-patching it, the function is brand new and thus unlikely to have been discovered by extension authors yet, and it's fairly thoroughly broken on those platforms anyway, so just fix it. Defect in 9da0cc3. Bug #15460. Back-patch to 11, where this function landed. Author: Thomas Munro Reported-by: Paul van der Linden, Pavel Oskin Reviewed-by: Peter Geoghegan Discussion: https://postgr.es/m/15460-b6db80de822fa0ad%40postgresql.org Discussion: https://postgr.es/m/CAHDGBJP_GsESbTt4P3FZA8kMUKuYxjg57XHF7NRBoKnR%3DCAR-g%40mail.gmail.com
1 parent eaf746a commit aa55183

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/backend/storage/file/buffile.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,17 +768,17 @@ BufFileTellBlock(BufFile *file)
768768
* Counts any holes left behind by BufFileAppend as part of the size.
769769
* Returns -1 on error.
770770
*/
771-
off_t
771+
int64
772772
BufFileSize(BufFile *file)
773773
{
774-
off_t lastFileSize;
774+
int64 lastFileSize;
775775

776776
/* Get the size of the last physical file. */
777777
lastFileSize = FileSize(file->files[file->numFiles - 1]);
778778
if (lastFileSize < 0)
779779
return -1;
780780

781-
return ((file->numFiles - 1) * (off_t) MAX_PHYSICAL_FILESIZE) +
781+
return ((file->numFiles - 1) * (int64) MAX_PHYSICAL_FILESIZE) +
782782
lastFileSize;
783783
}
784784

src/backend/utils/sort/logtape.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ ltsConcatWorkerTapes(LogicalTapeSet *lts, TapeShare *shared,
426426
{
427427
char filename[MAXPGPATH];
428428
BufFile *file;
429-
off_t filesize;
429+
int64 filesize;
430430

431431
lt = &lts->tapes[i];
432432

src/include/storage/buffile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extern size_t BufFileWrite(BufFile *file, void *ptr, size_t size);
4343
extern int BufFileSeek(BufFile *file, int fileno, off_t offset, int whence);
4444
extern void BufFileTell(BufFile *file, int *fileno, off_t *offset);
4545
extern int BufFileSeekBlock(BufFile *file, long blknum);
46-
extern off_t BufFileSize(BufFile *file);
46+
extern int64 BufFileSize(BufFile *file);
4747
extern long BufFileAppend(BufFile *target, BufFile *source);
4848

4949
extern BufFile *BufFileCreateShared(SharedFileSet *fileset, const char *name);

0 commit comments

Comments
 (0)