MinGW GCC issues print format warnings #142

Closed
opened 2017-09-20 12:19:30 +00:00 by karen-arutyunov · 0 comments
karen-arutyunov commented 2017-09-20 12:19:30 +00:00 (Migrated from github.com)

When build 64 bit target with MinGW GCC get the following warnings:

libpkgconf/client.c: In function 'pkgconf_trace':
libpkgconf/client.c:327:40: warning: unknown conversion type character 'l' in format [-Wformat=]
  len = snprintf(errbuf, sizeof errbuf, "%s:" SIZE_FMT_SPECIFIER " [%s]: ", filename, lineno, funcname);
                                        ^~~~~
In file included from libpkgconf/client.c:16:0:
./libpkgconf/stdinc.h:35:33: note: format string is defined here
#  define SIZE_FMT_SPECIFIER "%llu"
                                 ^
libpkgconf/client.c:327:40: warning: format '%s' expects argument of type 'char *', but argument 5 has type 'size_t {aka long long unsigned int}' [-Wformat=]
  len = snprintf(errbuf, sizeof errbuf, "%s:" SIZE_FMT_SPECIFIER " [%s]: ", filename, lineno, funcname);
                                        ^~~~~
libpkgconf/client.c:327:69: note: format string is defined here
  len = snprintf(errbuf, sizeof errbuf, "%s:" SIZE_FMT_SPECIFIER " [%s]: ", filename, lineno, funcname);
                                                                    ~^
                                                                    %I64d
libpkgconf/client.c:327:40: warning: too many arguments for format [-Wformat-extra-args]
  len = snprintf(errbuf, sizeof errbuf, "%s:" SIZE_FMT_SPECIFIER " [%s]: ", filename, lineno, funcname);
                                        ^~~~~
...

It seems that MinGW gcc (7.2.0) doesn't believe that msvcrt is C99 compliant in respect to 'll' size prefix.

Also when build 32 bit target with MinGW GCC get the following warnings:

libpkgconf/client.c: In function 'pkgconf_trace':
libpkgconf/client.c:327:40: warning: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'size_t {aka unsigned int}' [-Wformat=]
  len = snprintf(errbuf, sizeof errbuf, "%s:" SIZE_FMT_SPECIFIER " [%s]: ", filename, lineno, funcname);
                                        ^~~~~
In file included from libpkgconf/client.c:16:0:
./libpkgconf/stdinc.h:37:33: note: format string is defined here
 #  define SIZE_FMT_SPECIFIER "%lu"
                               ~~^
                               %u
 ...

Replacing

# ifdef _WIN64
#  define SIZE_FMT_SPECIFIER	"%llu"
# else
#  define SIZE_FMT_SPECIFIER	"%lu"
# endif

with

# ifdef _WIN64
#  define SIZE_FMT_SPECIFIER	"%I64u"
# else
#  define SIZE_FMT_SPECIFIER	"%u"
# endif

in stdinc.h fixes the issue for both 32 and 64 bit targets.

When build 64 bit target with MinGW GCC get the following warnings: ``` libpkgconf/client.c: In function 'pkgconf_trace': libpkgconf/client.c:327:40: warning: unknown conversion type character 'l' in format [-Wformat=] len = snprintf(errbuf, sizeof errbuf, "%s:" SIZE_FMT_SPECIFIER " [%s]: ", filename, lineno, funcname); ^~~~~ In file included from libpkgconf/client.c:16:0: ./libpkgconf/stdinc.h:35:33: note: format string is defined here # define SIZE_FMT_SPECIFIER "%llu" ^ libpkgconf/client.c:327:40: warning: format '%s' expects argument of type 'char *', but argument 5 has type 'size_t {aka long long unsigned int}' [-Wformat=] len = snprintf(errbuf, sizeof errbuf, "%s:" SIZE_FMT_SPECIFIER " [%s]: ", filename, lineno, funcname); ^~~~~ libpkgconf/client.c:327:69: note: format string is defined here len = snprintf(errbuf, sizeof errbuf, "%s:" SIZE_FMT_SPECIFIER " [%s]: ", filename, lineno, funcname); ~^ %I64d libpkgconf/client.c:327:40: warning: too many arguments for format [-Wformat-extra-args] len = snprintf(errbuf, sizeof errbuf, "%s:" SIZE_FMT_SPECIFIER " [%s]: ", filename, lineno, funcname); ^~~~~ ... ``` It seems that MinGW gcc (7.2.0) doesn't believe that msvcrt is C99 compliant in respect to 'll' size prefix. Also when build 32 bit target with MinGW GCC get the following warnings: ``` libpkgconf/client.c: In function 'pkgconf_trace': libpkgconf/client.c:327:40: warning: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'size_t {aka unsigned int}' [-Wformat=] len = snprintf(errbuf, sizeof errbuf, "%s:" SIZE_FMT_SPECIFIER " [%s]: ", filename, lineno, funcname); ^~~~~ In file included from libpkgconf/client.c:16:0: ./libpkgconf/stdinc.h:37:33: note: format string is defined here # define SIZE_FMT_SPECIFIER "%lu" ~~^ %u ... ``` Replacing ``` # ifdef _WIN64 # define SIZE_FMT_SPECIFIER "%llu" # else # define SIZE_FMT_SPECIFIER "%lu" # endif ``` with ``` # ifdef _WIN64 # define SIZE_FMT_SPECIFIER "%I64u" # else # define SIZE_FMT_SPECIFIER "%u" # endif ``` in stdinc.h fixes the issue for both 32 and 64 bit targets.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: ariadne/pkgconf#142
There is no content yet.