Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] lib: GCC format-overflow in G_recursive_remove #4471

Open
wenzeslaus opened this issue Oct 7, 2024 · 0 comments
Open

[Bug] lib: GCC format-overflow in G_recursive_remove #4471

wenzeslaus opened this issue Oct 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@wenzeslaus
Copy link
Member

wenzeslaus commented Oct 7, 2024

Describe the bug

Compilation of G_recursive_remove complains about "'%s' directive writing up to 255 bytes into a region of size between 1 and 4095" with -Wformat-overflow for sprintf(path2, "%s/%s", path, dp->d_name);.

To reproduce

Run compilation with -Wformat-overflow= (using GCC v13?) or in the nix develop environment.

Expected behavior

No errors or warnings, possibly warnings treated as errors.

Screenshots

gcc  -g -O2  -fPIC  -I/.../grass/dist.x86_64-pc-linux-gnu/include -I/.../grass/dist.x86_64-pc-linux-gnu/include    -DGRASS_VERSION_DATE=\"'2024'\" -DPACKAGE=\""grasslibs"\"        -I/.../grass/dist.x86_64-pc-linux-gnu/include -I/.../grass/dist.x86_64-pc-linux-gnu/include -DRELDIR=\"lib/gis\" -o OBJ.x86_64-pc-linux-gnu/set_window.o -c set_window.c
gcc  -g -O2  -fPIC  -I/.../grass/dist.x86_64-pc-linux-gnu/include -I/.../grass/dist.x86_64-pc-linux-gnu/include    -DGRASS_VERSION_DATE=\"'2024'\" -DPACKAGE=\""grasslibs"\"        -I/.../grass/dist.x86_64-pc-linux-gnu/include -I/.../grass/dist.x86_64-pc-linux-gnu/include -DRELDIR=\"lib/gis\" -o OBJ.x86_64-pc-linux-gnu/short_way.o -c short_way.c
remove.c: In function 'G_recursive_remove':
remove.c:132:28: warning: '%s' directive writing up to 255 bytes into a region of size between 1 and 4095 [-Wformat-overflow=]
  132 |         sprintf(path2, "%s/%s", path, dp->d_name);
      |                            ^~
In file included from /nix/store/wlavaybjbzgllhq11lib6qgr7rm8imgp-glibc-2.39-52-dev/include/stdio.h:980,
                 from remove.c:15:
In function 'sprintf',
    inlined from 'G_recursive_remove' at remove.c:132:9:
/nix/store/wlavaybjbzgllhq11lib6qgr7rm8imgp-glibc-2.39-52-dev/include/bits/stdio2.h:30:10: note: '__builtin___sprintf_chk' output between 2 and 4351 bytes into a destination of size 4096
   30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   31 |                                   __glibc_objsize (__s), __fmt,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   32 |                                   __va_arg_pack ());
      |                                   ~~~~~~~~~~~~~~~~~
gcc  -g -O2  -fPIC  -I/.../grass/dist.x86_64-pc-linux-gnu/include -I/.../grass/dist.x86_64-pc-linux-gnu/include    -DGRASS_VERSION_DATE=\"'2024'\" -DPACKAGE=\""grasslibs"\"        -I/.../grass/dist.x86_64-pc-linux-gnu/include -I/.../grass/dist.x86_64-pc-linux-gnu/include -DRELDIR=\"lib/gis\" -o OBJ.x86_64-pc-linux-gnu/sleep.o -c sleep.c

System description

  • Our nix develop environment on Ubuntu 22.04.
  • gcc (GCC) 13.3.0 (2023)
  • GRASS GIS 8.5.0dev 573d54a

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant