Skip to content

Commit 3ae8e8b

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 0d20252 commit 3ae8e8b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
635635
{
636636
instr_time start;
637637
instr_time duration;
638-
uint64 rows = 0;
638+
uint64 rows;
639639
BufferUsage bufusage;
640640

641641
bufusage = pgBufferUsage;
@@ -664,7 +664,15 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
664664

665665
/* parse command tag to retrieve the number of affected rows. */
666666
if (completionTag &&
667-
sscanf(completionTag, "COPY " UINT64_FORMAT, &rows) != 1)
667+
strncmp(completionTag, "COPY ", 5) == 0)
668+
{
669+
#ifdef HAVE_STRTOULL
670+
rows = strtoull(completionTag + 5, NULL, 10);
671+
#else
672+
rows = strtoul(completionTag + 5, NULL, 10);
673+
#endif
674+
}
675+
else
668676
rows = 0;
669677

670678
/* calc differences of buffer counters. */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy