Skip to content

Commit 9d7ded0

Browse files
committed
Avoid unportable usage of sscanf(UINT64_FORMAT).
On Mingw, it seems that scanf() doesn't necessarily accept the same format codes that printf() does, and in particular it may fail to recognize %llu even though printf() does. Since configure only probes printf() behavior while setting up the INT64_FORMAT macros, this means it's unsafe to use those macros with scanf(). We had only one instance of such a coding pattern, in contrib/pg_stat_statements, so change that code to avoid the problem. Per buildfarm warnings. Back-patch to 9.0 where the troublesome code was introduced. Michael Paquier
1 parent bf2e70b commit 9d7ded0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

contrib/pg_stat_statements/pg_stat_statements.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
962962
{
963963
instr_time start;
964964
instr_time duration;
965-
uint64 rows = 0;
965+
uint64 rows;
966966
BufferUsage bufusage_start,
967967
bufusage;
968968
uint32 queryId;
@@ -995,7 +995,15 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
995995

996996
/* parse command tag to retrieve the number of affected rows. */
997997
if (completionTag &&
998-
sscanf(completionTag, "COPY " UINT64_FORMAT, &rows) != 1)
998+
strncmp(completionTag, "COPY ", 5) == 0)
999+
{
1000+
#ifdef HAVE_STRTOULL
1001+
rows = strtoull(completionTag + 5, NULL, 10);
1002+
#else
1003+
rows = strtoul(completionTag + 5, NULL, 10);
1004+
#endif
1005+
}
1006+
else
9991007
rows = 0;
10001008

10011009
/* calc differences of buffer counters. */

0 commit comments

Comments
 (0)