Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit98c6231

Browse files
committed
Fix incorrect data type choices in some read and write calls.
Recently-introduced code in reconstruct.c was using "unsigned"to store the result of read(), pg_pread(), or write(). This iscompletely bogus: it breaks subsequent tests for the result beingnegative, as we're being reminded of by a chorus of buildfarmwarnings. Switch to "int" as was doubtless intended. (There areseveral other uses of "unsigned" in this file that also look poorlychosen to me, but for now I'm just trying to clean up the buildfarm.)A larger problem is that "int" is not necessarily wide enough to holdthe result: per POSIX, all these functions return ssize_t. In placeswhere the requested read or write length clearly fits in int, that'sacademic. It may be academic anyway as long as we constrainindividual data files to 1GB, since even a readv or writev-likeoperation would then not be responsible for transferring more than1GB. Nonetheless it seems like trouble waiting to happen, so I madea pass over readv and writev calls and fixed the result variableswhere that seemed appropriate. We might want to think about changingsome of the fd.c functions to return ssize_t too, for future-proofing;but I didn't tackle that here.Discussion:https://postgr.es/m/1672202.1703441340@sss.pgh.pa.us
1 parentda083b2 commit98c6231

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2280,7 +2280,7 @@ XLogWrite(XLogwrtRqst WriteRqst, TimeLineID tli, bool flexible)
22802280
char*from;
22812281
Sizenbytes;
22822282
Sizenleft;
2283-
intwritten;
2283+
ssize_twritten;
22842284
instr_timestart;
22852285

22862286
/* OK to write the page(s) */

‎src/backend/backup/basebackup.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ static void perform_base_backup(basebackup_options *opt, bbsink *sink,
117117
IncrementalBackupInfo*ib);
118118
staticvoidparse_basebackup_options(List*options,basebackup_options*opt);
119119
staticintcompareWalFileNames(constListCell*a,constListCell*b);
120-
staticintbasebackup_read_file(intfd,char*buf,size_tnbytes,off_toffset,
121-
constchar*filename,boolpartial_read_ok);
120+
staticssize_tbasebackup_read_file(intfd,char*buf,size_tnbytes,off_toffset,
121+
constchar*filename,boolpartial_read_ok);
122122

123123
/* Was the backup currently in-progress initiated in recovery mode? */
124124
staticboolbackup_started_in_recovery= false;
@@ -525,7 +525,7 @@ perform_base_backup(basebackup_options *opt, bbsink *sink,
525525
{
526526
char*walFileName= (char*)lfirst(lc);
527527
intfd;
528-
size_tcnt;
528+
ssize_tcnt;
529529
pgoff_tlen=0;
530530

531531
snprintf(pathbuf,MAXPGPATH,XLOGDIR"/%s",walFileName);
@@ -2079,11 +2079,11 @@ convert_link_to_directory(const char *pathbuf, struct stat *statbuf)
20792079
*
20802080
* Returns the number of bytes read.
20812081
*/
2082-
staticint
2082+
staticssize_t
20832083
basebackup_read_file(intfd,char*buf,size_tnbytes,off_toffset,
20842084
constchar*filename,boolpartial_read_ok)
20852085
{
2086-
intrc;
2086+
ssize_trc;
20872087

20882088
pgstat_report_wait_start(WAIT_EVENT_BASEBACKUP_READ);
20892089
rc=pg_pread(fd,buf,nbytes,offset);
@@ -2096,7 +2096,7 @@ basebackup_read_file(int fd, char *buf, size_t nbytes, off_t offset,
20962096
if (!partial_read_ok&&rc>0&&rc!=nbytes)
20972097
ereport(ERROR,
20982098
(errcode_for_file_access(),
2099-
errmsg("could not read file \"%s\": read %d of %zu",
2099+
errmsg("could not read file \"%s\": read %zd of %zu",
21002100
filename,rc,nbytes)));
21012101

21022102
returnrc;

‎src/bin/pg_combinebackup/reconstruct.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,15 @@ make_rfile(char *filename, bool missing_ok)
504504
staticvoid
505505
read_bytes(rfile*rf,void*buffer,unsignedlength)
506506
{
507-
unsignedrb=read(rf->fd,buffer,length);
507+
intrb=read(rf->fd,buffer,length);
508508

509509
if (rb!=length)
510510
{
511511
if (rb<0)
512512
pg_fatal("could not read file \"%s\": %m",rf->filename);
513513
else
514514
pg_fatal("could not read file \"%s\": read only %d of %d bytes",
515-
rf->filename,(int)rb,length);
515+
rf->filename,rb,length);
516516
}
517517
}
518518

@@ -614,7 +614,7 @@ write_reconstructed_file(char *input_filename,
614614
{
615615
uint8buffer[BLCKSZ];
616616
rfile*s=sourcemap[i];
617-
unsignedwb;
617+
intwb;
618618

619619
/* Update accounting information. */
620620
if (s==NULL)
@@ -641,7 +641,7 @@ write_reconstructed_file(char *input_filename,
641641
}
642642
else
643643
{
644-
unsignedrb;
644+
intrb;
645645

646646
/* Read the block from the correct source, except if dry-run. */
647647
rb=pg_pread(s->fd,buffer,BLCKSZ,offsetmap[i]);
@@ -650,9 +650,9 @@ write_reconstructed_file(char *input_filename,
650650
if (rb<0)
651651
pg_fatal("could not read file \"%s\": %m",s->filename);
652652
else
653-
pg_fatal("could not read file \"%s\": read only %d of %d bytes at offset %u",
654-
s->filename,(int)rb,BLCKSZ,
655-
(unsigned)offsetmap[i]);
653+
pg_fatal("could not read file \"%s\": read only %d of %d bytes at offset %llu",
654+
s->filename,rb,BLCKSZ,
655+
(unsigned long long)offsetmap[i]);
656656
}
657657
}
658658

@@ -663,7 +663,7 @@ write_reconstructed_file(char *input_filename,
663663
pg_fatal("could not write file \"%s\": %m",output_filename);
664664
else
665665
pg_fatal("could not write file \"%s\": wrote only %d of %d bytes",
666-
output_filename,(int)wb,BLCKSZ);
666+
output_filename,wb,BLCKSZ);
667667
}
668668

669669
/* Update the checksum computation. */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp