https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83139

            Bug ID: 83139
           Summary: error: null destination pointer
                    [-Werror=format-truncation=] for second call with same
                    destination pointer
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: j...@jak-linux.org
  Target Milestone: ---

Created attachment 42701
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42701&action=edit
Example

In the attached example (minified proxychains common.c), there are two cases of
snprintf(pbuf, bufsize, in a function. The second one causes an error, at -O2
or higher:

$ gcc -Wall -Werror -O2 -c -v -save-temps common.c
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 7.2.0-16'
--with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-7
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie
--with-system-zlib --with-target-system-zlib --enable-objc-gc=auto
--enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 7.2.0 (Debian 7.2.0-16) 
COLLECT_GCC_OPTIONS='-Wall' '-Werror' '-O2' '-c' '-v' '-save-temps'
'-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/7/cc1 -E -quiet -v -imultiarch x86_64-linux-gnu
common.c -mtune=generic -march=x86-64 -Wall -Werror -O2 -fpch-preprocess -o
common.i
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/7/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-Wall' '-Werror' '-O2' '-c' '-v' '-save-temps'
'-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/7/cc1 -fpreprocessed common.i -quiet -dumpbase
common.c -mtune=generic -march=x86-64 -auxbase common -O2 -Wall -Werror
-version -o common.s
GNU C11 (Debian 7.2.0-16) version 7.2.0 (x86_64-linux-gnu)
        compiled by GNU C version 7.2.0, GMP version 6.1.2, MPFR version 3.1.6,
MPC version 1.0.3, isl version isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C11 (Debian 7.2.0-16) version 7.2.0 (x86_64-linux-gnu)
        compiled by GNU C version 7.2.0, GMP version 6.1.2, MPFR version 3.1.6,
MPC version 1.0.3, isl version isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 4f65f393f8f34cf4758c10c601ec207f
common.c: In function ‘get_config_path’:
common.c:29:2: error: null destination pointer [-Werror=format-truncation=]
  snprintf(pbuf, bufsize, "%s/.proxychains/%s", path, PROXYCHAINS_CONF_FILE);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors


If the pointer was not NULL before, and there is no char** pointer at all,
there seems to be no way it could suddenly become NULL, so the error is wrong.

Reply via email to