From: Tom Lane Date: Tue, 27 May 2014 02:23:39 +0000 (-0400) Subject: Avoid unportable usage of sscanf(UINT64_FORMAT). X-Git-Tag: REL9_1_14~36 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3ae8e8bf552f622600b1a356550882e886753119;p=postgresql 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 --- diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index 468282ec99..5793068446 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -635,7 +635,7 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString, { instr_time start; instr_time duration; - uint64 rows = 0; + uint64 rows; BufferUsage bufusage; bufusage = pgBufferUsage; @@ -664,7 +664,15 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString, /* parse command tag to retrieve the number of affected rows. */ if (completionTag && - sscanf(completionTag, "COPY " UINT64_FORMAT, &rows) != 1) + strncmp(completionTag, "COPY ", 5) == 0) + { +#ifdef HAVE_STRTOULL + rows = strtoull(completionTag + 5, NULL, 10); +#else + rows = strtoul(completionTag + 5, NULL, 10); +#endif + } + else rows = 0; /* calc differences of buffer counters. */