8000 Fix aboriginal bug in _tarAddFile(): when complaining that the amount… · danielcode/postgres@85738a5 · GitHub
[go: up one dir, main page]

Skip to content < 8000 link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/keyboard-shortcuts-dialog.47de85e2c17af43cefd5.module.css" />

Commit 85738a5

Browse files
committed
Fix aboriginal bug in _tarAddFile(): when complaining that the amount of data
read from the temp file didn't match the file length reported by ftello(), the wrong variable's value was printed, and so the message made no sense. Clean up a couple other coding infelicities while at it.
1 parent 10a81b3 commit 85738a5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/bin/pg_dump/pg_backup_tar.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.32.2.3 2007/08/06 01:38:57 tgl Exp $
19+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.32.2.4 2007/08/29 16:32:11 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -1021,15 +1021,16 @@ _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th)
10211021
*/
10221022
fseeko(tmp, 0, SEEK_END);
10231023
th->fileLen = ftello(tmp);
1024+
fseeko(tmp, 0, SEEK_SET);
1025+
10241026
if (th->fileLen > MAX_TAR_MEMBER_FILELEN)
10251027
die_horribly(AH, modulename, "archive member too large for tar format\n");
1026-
fseeko(tmp, 0, SEEK_SET);
10271028

10281029
_tarWriteHeader(th);
10291030

1030-
while ((cnt = fread(&buf[0], 1, 32767, tmp)) > 0)
1031+
while ((cnt = fread(buf, 1, sizeof(buf), tmp)) > 0)
10311032
{
1032-
res = fwrite(&buf[0], 1, cnt, th->tarFH);
1033+
res = fwrite(buf, 1, cnt, th->tarFH);
10331034
if (res != cnt)
10341035
die_horribly(AH, modulename,
10351036
"write error appending to tar archive (wrote %lu, attempted %lu)\n",
@@ -1038,15 +1039,16 @@ _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th)
10381039
}
10391040

10401041
if (fclose(tmp) != 0) /* This *should* delete it... */
1041-
die_horribly(AH, modulename, "could not close tar member: %s\n", strerror(errno));
1042+
die_horribly(AH, modulename, "could not close tar member: %s\n",
1043+
strerror(errno));
10421044

10431045
if (len != th->fileLen)
10441046
{
1045-
char buf1[100],
1046-
buf2[100];
1047+
char buf1[32],
1048+
buf2[32];
10471049

1048-
snprintf(buf1, 100, INT64_FORMAT, (int64) len);
1049-
snprintf(buf2, 100, INT64_FORMAT, (int64) th->pos);
1050+
snprintf(buf1, sizeof(buf1), INT64_FORMAT, (int64) len);
1051+
snprintf(buf2, sizeof(buf2), INT64_FORMAT, (int64) th->fileLen);
10501052
die_horribly(AH, modulename, "actual file length (%s) does not match expected (%s)\n",
10511053
buf1, buf2);
10521054
}

0 commit comments

Comments
 (0)
0