eserte / perl-tk

the perl module Tk
https://metacpan.org/release/Tk
Other
44 stars 31 forks source link

new warning with GCC 13: ‘Tix_GrAddChangedRect’ accessing 16 bytes in a region of size 8 [-Wstringop-overflow] #108

Open Quipyowert2 opened 2 months ago

Quipyowert2 commented 2 months ago

GCC 13 gives a false positive on tixGrSel.c in Perl/Tk 804.036:

cc -c -I/usr/include/freetype2  -I..  -I/usr/include/freetype2 -I. -Ibitmaps  -I/usr/include/freetype2 -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -O2   -DVERSION=\"804.036\" -DXS_VERSION=\"804.036\" -fPIC "-I/home/nathan/perl5/perlbrew/perls/perl-5.41.2/lib/5.41.2/x86_64-linux/CORE"    tixGrSel.c
In function ‘Tix_GrMergeSelection’,
    inlined from ‘Tix_GrSelModify’ at tixGrSel.c:377:2:
tixGrSel.c:233:5: warning: ‘Tix_GrAddChangedRect’ accessing 16 bytes in a region of size 8 [-Wstringop-overflow=]
  233 |     Tix_GrAddChangedRect(wPtr, sbPtr->range, 0);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tixGrSel.c:233:5: note: referencing argument 2 of type ‘int[2][2]’
In file included from tixGrSel.c:19:
tixGrid.h: In function ‘Tix_GrSelModify’:
tixGrid.h:388:25: note: in a call to function ‘Tix_GrAddChangedRect’
  388 | EXTERN void             Tix_GrAddChangedRect _ANSI_ARGS_((
      |                         ^~~~~~~~~~~~~~~~~~~~

Tix_GrMergeSelection() calls Tix_GrAddChangedRect with sbPtr->range which is of type int[2][2]. The function Tix_GrAddChangedRect() takes a parameter of type int[2][2]. These types seem to both be the same array of arrays, having a total length of 16, but apparently, the type is decaying to int(*)[2] somewhere, causing GCC to think the parameter is only 8 bytes instead of 16. sizeof(int) is 4 bytes, I think. GCC 11 gives -Wstringop-overflow when no string op is used links to GCC 11 bug report 101854 in a similar situation.

Turns out that -Wstringop-overflow is broken. Gcc bug 88443 has the entire list of -Wstringop-overflow bugs.

I am using Perl 5.41.2, installed with Perlbrew, inside the openSUSE Tumbleweed distro in WSL2.

Both the CPAN version of Perl/Tk and the latest GitHub version have the same warning.

VERSIONS

Perl 5.41.2 (installed from source with Perlbrew) GCC 13.3.0 (official Tumbleweed package) GLIBC 2.39 (official Tumbleweed package) openSUSE Tumbleweed 20240725-0 (Last month's snapshot) perl-Tk version: 804.036-18-gf0bb386b WSL2 version:

WSL version: 2.2.4.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.61
MSRDC version: 1.2.5326
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26091.1-240325-1447.ge-release
Windows version: 10.0.19045.4780
perl -V ``` Summary of my perl5 (revision 5 version 41 subversion 2) configuration: Platform: osname=linux osvers=5.15.153.1-microsoft-standard-wsl2 archname=x86_64-linux uname='linux msi 5.15.153.1-microsoft-standard-wsl2 #1 smp fri mar 29 23:14:13 utc 2024 x86_64 x86_64 x86_64 gnulinux ' config_args='-de -Dprefix=/home/nathan/perl5/perlbrew/perls/perl-5.41.2 -Dusedevel -Aeval:scriptdir=/home/nathan/perl5/perlbrew/perls/perl-5.41.2/bin' hint=recommended useposix=true d_sigaction=define useithreads=undef usemultiplicity=undef use64bitint=define use64bitall=define uselongdouble=undef usemymalloc=n default_inc_excludes_dot=define Compiler: cc='cc' ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2' optimize='-O2' cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include' ccversion='' gccversion='13.3.0' gccosandvers='' intsize=4 longsize=8 ptrsize=8 doublesize=8 byteorder=12345678 doublekind=3 d_longlong=define longlongsize=8 d_longdbl=define longdblsize=16 longdblkind=3 ivtype='long' ivsize=8 nvtype='double' nvsize=8 Off_t='off_t' lseeksize=8 alignbytes=8 prototype=define Linker and Libraries: ld='cc' ldflags =' -fstack-protector-strong -L/usr/local/lib' libpth=/usr/local/lib /usr/x86_64-suse-linux/lib /usr/lib /usr/lib64 /usr/local/lib64 libs=-lpthread -ldl -lm -lcrypt -lutil -lc perllibs=-lpthread -ldl -lm -lcrypt -lutil -lc libc=/lib/../lib64/libc.so.6 so=so useshrplib=false libperl=libperl.a gnulibc_version='2.39' Dynamic Linking: dlsrc=dl_dlopen.xs dlext=so d_dlsymun=undef ccdlflags='-Wl,-E' cccdlflags='-fPIC' lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong' Characteristics of this binary (from libperl): Compile-time options: HAS_LONG_DOUBLE HAS_STRTOLD HAS_TIMES PERLIO_LAYERS PERL_COPY_ON_WRITE PERL_DONT_CREATE_GVSV PERL_HASH_FUNC_SIPHASH13 PERL_HASH_USE_SBOX32 PERL_MALLOC_WRAP PERL_OP_PARENT PERL_PRESERVE_IVUV PERL_USE_DEVEL PERL_USE_SAFE_PUTENV USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_LOCALE_TIME USE_PERLIO USE_PERL_ATOF Built under linux Compiled at Aug 20 2024 15:21:53 %ENV: PERLBREW_HOME="/home/nathan/.perlbrew" PERLBREW_MANPATH="/home/nathan/perl5/perlbrew/perls/perl-5.41.2/man" PERLBREW_PATH="/home/nathan/perl5/perlbrew/bin:/home/nathan/perl5/perlbrew/perls/perl-5.41.2/bin" PERLBREW_PERL="perl-5.41.2" PERLBREW_ROOT="/home/nathan/perl5/perlbrew" PERLBREW_SHELLRC_VERSION="0.98" PERLBREW_VERSION="0.98" @INC: /home/nathan/perl5/perlbrew/perls/perl-5.41.2/lib/site_perl/5.41.2/x86_64-linux /home/nathan/perl5/perlbrew/perls/perl-5.41.2/lib/site_perl/5.41.2 /home/nathan/perl5/perlbrew/perls/perl-5.41.2/lib/5.41.2/x86_64-linux /home/nathan/perl5/perlbrew/perls/perl-5.41.2/lib/5.41.2 ```