Skip to content

Commit c917660

Browse files
committed
Workaround for format strings that are concatenated from macros
(INT64_FORMAT), which gettext cannot handle.
1 parent 738d138 commit c917660

File tree

2 files changed

+85
-27
lines changed

2 files changed

+85
-27
lines changed

src/backend/commands/sequence.c

+48-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.85 2002/08/30 19:23:19 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.86 2002/09/03 18:50:54 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -400,8 +400,12 @@ nextval(PG_FUNCTION_ARGS)
400400
if (rescnt > 0)
401401
break; /* stop fetching */
402402
if (!seq->is_cycled)
403-
elog(ERROR, "%s.nextval: reached MAXVALUE (" INT64_FORMAT ")",
404-
sequence->relname, maxv);
403+
{
404+
char buf[100];
405+
snprintf(buf, 100, INT64_FORMAT, maxv);
406+
elog(ERROR, "%s.nextval: reached MAXVALUE (%s)",
407+
sequence->relname, buf);
408+
}
405409
next = minv;
406410
}
407411
else
@@ -416,8 +420,12 @@ nextval(PG_FUNCTION_ARGS)
416420
if (rescnt > 0)
417421
break; /* stop fetching */
418422
if (!seq->is_cycled)
419-
elog(ERROR, "%s.nextval: reached MINVALUE (" INT64_FORMAT ")",
420-
sequence->relname, minv);
423+
{
424+
char buf[100];
425+
snprintf(buf, 100, INT64_FORMAT, minv);
426+
elog(ERROR, "%s.nextval: reached MINVALUE (%s)",
427+
sequence->relname, buf);
428+
}
421429
next = maxv;
422430
}
423431
else
@@ -551,8 +559,14 @@ do_setval(RangeVar *sequence, int64 next, bool iscalled)
551559
seq = read_info("setval", elm, seqrel, &buf);
552560

553561
if ((next < seq->min_value) || (next > seq->max_value))
554-
elog(ERROR, "%s.setval: value " INT64_FORMAT " is out of bounds (" INT64_FORMAT "," INT64_FORMAT ")",
555-
sequence->relname, next, seq->min_value, seq->max_value);
562+
{
563+
char bufv[100], bufm[100], bufx[100];
564+
snprintf(bufv, 100, INT64_FORMAT, next);
565+
snprintf(bufm, 100, INT64_FORMAT, seq->min_value);
566+
snprintf(bufx, 100, INT64_FORMAT, seq->max_value);
567+
elog(ERROR, "%s.setval: value %s is out of bounds (%s,%s)",
568+
sequence->relname, bufv, bufm, bufx);
569+
}
556570

557571
/* save info in local cache */
558572
elm->last = next; /* last returned number */
@@ -813,8 +827,13 @@ init_params(CreateSeqStmt *seq, Form_pg_sequence new)
813827
new->min_value = defGetInt64(min_value);
814828

815829
if (new->min_value >= new->max_value)
816-
elog(ERROR, "DefineSequence: MINVALUE (" INT64_FORMAT ") can't be >= MAXVALUE (" INT64_FORMAT ")",
817-
new->min_value, new->max_value);
830+
{
831+
char bufm[100], bufx[100];
832+
snprintf(bufm, 100, INT64_FORMAT, new->min_value);
833+
snprintf(bufx, 100, INT64_FORMAT, new->max_value);
834+
elog(ERROR, "DefineSequence: MINVALUE (%s) must be less than MAXVALUE (%s)",
835+
bufm, bufx);
836+
}
818837

819838
if (last_value == (DefElem *) NULL) /* START WITH */
820839
{
@@ -827,17 +846,31 @@ init_params(CreateSeqStmt *seq, Form_pg_sequence new)
827846
new->last_value = defGetInt64(last_value);
828847

829848
if (new->last_value < new->min_value)
830-
elog(ERROR, "DefineSequence: START value (" INT64_FORMAT ") can't be < MINVALUE (" INT64_FORMAT ")",
831-
new->last_value, new->min_value);
849+
{
850+
char bufs[100], bufm[100];
851+
snprintf(bufs, 100, INT64_FORMAT, new->last_value);
852+
snprintf(bufm, 100, INT64_FORMAT, new->min_value);
853+
elog(ERROR, "DefineSequence: START value (%s) can't be less than MINVALUE (%s)",
854+
bufs, bufm);
855+
}
832856
if (new->last_value > new->max_value)
833-
elog(ERROR, "DefineSequence: START value (" INT64_FORMAT ") can't be > MAXVALUE (" INT64_FORMAT ")",
834-
new->last_value, new->max_value);
857+
{
858+
char bufs[100], bufm[100];
859+
snprintf(bufs, 100, INT64_FORMAT, new->last_value);
860+
snprintf(bufm, 100, INT64_FORMAT, new->max_value);
861+
elog(ERROR, "DefineSequence: START value (%s) can't be greater than MAXVALUE (%s)",
862+
bufs, bufm);
863+
}
835864

836865
if (cache_value == (DefElem *) NULL) /* CACHE */
837866
new->cache_value = 1;
838867
else if ((new->cache_value = defGetInt64(cache_value)) <= 0)
839-
elog(ERROR, "DefineSequence: CACHE (" INT64_FORMAT ") can't be <= 0",
840-
new->cache_value);
868+
{
869+
char buf[100];
870+
snprintf(buf, 100, INT64_FORMAT, new->cache_value);
871+
elog(ERROR, "DefineSequence: CACHE (%s) can't be <= 0",
872+
buf);
873+
}
841874

842875
}
843876

src/bin/pg_dump/pg_backup_tar.c

+37-12
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.26 2002/08/28 20:46:24 momjian Exp $
19+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.27 2002/09/03 18:50:54 petere Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -1024,8 +1024,13 @@ _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th)
10241024
die_horribly(AH, modulename, "could not close tar member: %s\n", strerror(errno));
10251025

10261026
if (len != th->fileLen)
1027-
die_horribly(AH, modulename, "actual file length (" INT64_FORMAT ") does not match expected (" INT64_FORMAT ")\n",
1028-
(int64) len, (int64) th->pos);
1027+
{
1028+
char buf1[100], buf2[100];
1029+
snprintf(buf1, 100, INT64_FORMAT, (int64) len);
1030+
snprintf(buf2, 100, INT64_FORMAT, (int64) th->pos);
1031+
die_horribly(AH, modulename, "actual file length (%s) does not match expected (%s)\n",
1032+
buf1, buf2);
1033+
}
10291034

10301035
pad = ((len + 511) & ~511) - len;
10311036
for (i = 0; i < pad; i++)
@@ -1055,14 +1060,21 @@ _tarPositionTo(ArchiveHandle *AH, const char *filename)
10551060
/* Go to end of current file, if any */
10561061
if (ctx->tarFHpos != 0)
10571062
{
1058-
ahlog(AH, 4, "moving from position " INT64_FORMAT " to next member at file position " INT64_FORMAT "\n",
1059-
(int64) ctx->tarFHpos, (int64) ctx->tarNextMember);
1063+
char buf1[100], buf2[100];
1064+
snprintf(buf1, 100, INT64_FORMAT, (int64) ctx->tarFHpos);
1065+
snprintf(buf2, 100, INT64_FORMAT, (int64) ctx->tarNextMember);
1066+
ahlog(AH, 4, "moving from position %s to next member at file position %s\n",
1067+
buf1, buf2);
10601068

10611069
while (ctx->tarFHpos < ctx->tarNextMember)
10621070
_tarReadRaw(AH, &c, 1, NULL, ctx->tarFH);
10631071
}
10641072

1065-
ahlog(AH, 4, "now at file position " INT64_FORMAT "\n", (int64) ctx->tarFHpos);
1073+
{
1074+
char buf[100];
1075+
snprintf(buf, 100, INT64_FORMAT, (int64) ctx->tarFHpos);
1076+
ahlog(AH, 4, "now at file position %s\n", buf);
1077+
}
10661078

10671079
/* We are at the start of the file. or at the next member */
10681080

@@ -1125,9 +1137,14 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
11251137
{
11261138
#if 0
11271139
if (ftello(ctx->tarFH) != ctx->tarFHpos)
1140+
{
1141+
char buf1[100], buf2[100];
1142+
snprintf(buf1, 100, INT64_FORMAT, (int64) ftello(ctx->tarFH));
1143+
snprintf(buf2, 100, INT64_FORMAT, (int64) ftello(ctx->tarFHpos));
11281144
die_horribly(AH, modulename,
1129-
"mismatch in actual vs. predicted file position (" INT64_FORMAT " vs. " INT64_FORMAT ")\n",
1130-
(int64) ftello(ctx->tarFH), (int64) ctx->tarFHpos);
1145+
"mismatch in actual vs. predicted file position (%s vs. %s)\n",
1146+
buf1, buf2);
1147+
}
11311148
#endif
11321149

11331150
/* Save the pos for reporting purposes */
@@ -1170,14 +1187,22 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
11701187
sscanf(&h[124], "%12o", &len);
11711188
sscanf(&h[148], "%8o", &sum);
11721189

1173-
ahlog(AH, 3, "TOC Entry %s at " INT64_FORMAT " (length %lu, checksum %d)\n",
1174-
&tag[0], (int64) hPos, (unsigned long) len, sum);
1190+
{
1191+
char buf[100];
1192+
snprintf(buf, 100, INT64_FORMAT, (int64) hPos);
1193+
ahlog(AH, 3, "TOC Entry %s at %s (length %lu, checksum %d)\n",
1194+
&tag[0], buf, (unsigned long) len, sum);
1195+
}
11751196

11761197
if (chk != sum)
1198+
{
1199+
char buf[100];
1200+
snprintf(buf, 100, INT64_FORMAT, (int64) ftello(ctx->tarFH));
11771201
die_horribly(AH, modulename,
11781202
"corrupt tar header found in %s "
1179-
"(expected %d, computed %d) file position " INT64_FORMAT "\n",
1180-
&tag[0], sum, chk, (int64) ftello(ctx->tarFH));
1203+
"(expected %d, computed %d) file position %s\n",
1204+
&tag[0], sum, chk, buf);
1205+
}
11811206

11821207
th->targetFile = strdup(tag);
11831208
th->fileLen = len;

0 commit comments

Comments
 (0)