Menu

#846 wprintf, swprintf etc. don't check format specifiers vs. arguments on compile

v1.0 (example)
open
nobody
None
5
2020-06-20
2020-06-19
David Macek
No

Source:

#define __USE_MINGW_ANSI_STDIO 1
#define _UNICODE
#include <stdio.h>
#include <wchar.h>

int wmain(int argc, wchar_t *argv[]) {
    wprintf(L"argc=%d argv[0]=%s", argc, argv[0]);
    return 0;
}

Observed behavior:

> gcc -municode -std=c11 -Wall -Wextra -Werror -pedantic example.c -o example.exe
> example.exe
argc=1 argv[0]=e

Expected behavior:

GCC emits an error during compilation.

Version:

> gcc -v
 Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=D:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/10.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-10.1.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++ --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --disable-plugin --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev3, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.1.0 (Rev3, Built by MSYS2 project)

Related

Bugs: #846

Discussion

  • Kai Tietz

    Kai Tietz - 2020-06-19

    Hello,

    Well, I would not say that diagnostic is wrong here. As for
    wide-character routine '%s' still represents an array of characters,
    means here an array of wchar_t. For futher reading please see
    https://man7.org/linux/man-pages/man3/wprintf.3.html

    Regards,
    Kai

    Am Fr., 19. Juni 2020 um 10:48 Uhr schrieb David Macek
    elieux@users.sourceforge.net:


    [bugs:#846] wprintf, swprintf etc. don't check format specifiers vs. arguments on compile

    Status: open
    Group: v1.0 (example)
    Created: Fri Jun 19, 2020 08:48 AM UTC by David Macek
    Last Updated: Fri Jun 19, 2020 08:48 AM UTC
    Owner: nobody

    Source:

    define __USE_MINGW_ANSI_STDIO 1

    define _UNICODE

    include <stdio.h></stdio.h>

    include <wchar.h></wchar.h>

    int wmain(int argc, wchar_t *argv[]) {
    wprintf(L"argc=%d argv[0]=%s", argc, argv[0]);
    return 0;
    }

    Observed behavior:

    gcc -municode -std=c11 -Wall -Wextra -Werror -pedantic example.c -o example.exe
    example.exe
    argc=1 argv[0]=e

    Expected behavior:

    GCC emits an error during compilation.

    Version:

    gcc -v
    Using built-in specs.
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=D:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/10.1.0/lto-wrapper.exe
    Target: x86_64-w64-mingw32
    Configured with: ../gcc-10.1.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++ --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --disable-plugin --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev3, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
    Thread model: posix
    Supported LTO compression algorithms: zlib zstd
    gcc version 10.1.0 (Rev3, Built by MSYS2 project)


    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/mingw-w64/bugs/846/

    To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

     

    Related

    Bugs: #846

    • David Macek

      David Macek - 2020-06-19

      The diagnostic reports an error in the reverse situation, why should it not report both?

      #define __USE_MINGW_ANSI_STDIO 1
      #include <stdio.h>
      
      int main(int argc, char *argv[]) {
          printf("argc=%d argv[0]=%ls", argc, argv[0]);
      
          return 0;
      }
      
      > gcc -std=c11 -Wall -Wextra -Werror -pedantic narrow.c
      a.c: In function 'main':
      a.c:7:28: error: format '%ls' expects argument of type 'wchar_t *', but argument 3 has type 'char *' [-Werror=format=]
          7 |  printf("argc=%d argv[0]=%ls", argc, argv[0]);
            |                          ~~^         ~~~~~~~
            |                            |             |
            |                            |             char *
            |                            short unsigned int *
            |                          %s
      cc1.exe: all warnings being treated as errors
      
       
  • David Macek

    David Macek - 2020-06-20

    I think I may have missed the point here with the example. Let me try again:

    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
        wprintf(L"argc=%f argv[0]=%d", argc, argv[0]);
        return 0;
    }
    
    > gcc -std=c11 -Wall -Wextra -Werror -pedantic example.c -o example.exe
    > example.exe
    argc=0.000000 argv[0]=11408304
    

    This surely deserves some warnings. :)

     

Log in to post a comment.