cxong / cdogs-sdl

Classic overhead run-and-gun game
https://cxong.github.io/cdogs-sdl/
GNU General Public License v2.0
887 stars 114 forks source link

The game fails to compile on newer compilers #615

Closed Rampoina closed 4 years ago

Rampoina commented 4 years ago

Relevant log below:


src/cdogsed/cdogsed.c:394:13: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size between 0 and 4095 [-Wformat-overflow=]
  394 |    buf, "%s~%d%s", dirname, sAutosaveIndex, PathGetBasename(lastFile));
      |             ^~
In file included from /usr/include/stdio.h:867,
                 from src/cdogsed/cdogsed.c:51:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output 3 or more bytes (assuming 4098) into a destination of size 4096
   36 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |       __bos (__s), __fmt, __va_arg_pack ());
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/cdogsed/cdogsed.c: In function ‘main’:
src/cdogsed/cdogsed.c:659:29: warning: ‘%s’ directive writing up to 4095 bytes into a region of size 4087 [-Wformat-overflow=]
  659 |   sprintf(msgBuf, "Saved to %s", filename);
      |                             ^~   ~~~~~~~~
In file included from /usr/include/stdio.h:867,
                 from src/cdogsed/cdogsed.c:51:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 10 and 4105 bytes into a destination of size 4096
   36 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |       __bos (__s), __fmt, __va_arg_pack ());
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/cdogsed/cdogsed.c:554:20: warning: ‘.cdogscpn’ directive writing 9 bytes into a region of size between 1 and 4096 [-Wformat-overflow=]
  554 |    sprintf(buf, "%s.cdogscpn", filename);
      |                    ^~~~~~~~~
In file included from /usr/include/stdio.h:867,
                 from src/cdogsed/cdogsed.c:51:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 10 and 4105 bytes into a destination of size 4096
   36 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |       __bos (__s), __fmt, __va_arg_pack ());
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/cdogsed/cdogsed.c:560:20: warning: ‘.cpn’ directive writing 4 bytes into a region of size between 1 and 4096 [-Wformat-overflow=]
  560 |    sprintf(buf, "%s.cpn", filename);
      |                    ^~~~
In file included from /usr/include/stdio.h:867,
                 from src/cdogsed/cdogsed.c:51:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 5 and 4100 bytes into a destination of size 4096
   36 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |       __bos (__s), __fmt, __va_arg_pack ());
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[10/208] Building C object src/CMakeFiles/cdogs-sdl.dir/hiscores.c.o
src/hiscores.c: In function ‘HighScoreDraw’:
src/hiscores.c:213:14: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 10 [-Wformat-overflow=]
  213 |  sprintf(s, "%d.", idx + 1);
      |              ^~
src/hiscores.c:213:13: note: directive argument in the range [-2147483647, 20]
  213 |  sprintf(s, "%d.", idx + 1);
      |             ^~~~~
In file included from /usr/include/stdio.h:867,
                 from src/json/json.h:31,
                 from src/cdogs/cpic.h:30,
                 from src/cdogs/character_class.h:31,
                 from src/cdogs/character.h:32,
                 from src/cdogs/campaigns.h:33,
                 from src/hiscores.h:51,
                 from src/hiscores.c:49:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 3 and 13 bytes into a destination of size 10
   36 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |       __bos (__s), __fmt, __va_arg_pack ());
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/hiscores.c:219:15: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 9 [-Wformat-overflow=]
  219 |  sprintf(s, "(%d)", e->lastMission + 1);
      |               ^~
src/hiscores.c:219:13: note: directive argument in the range [-2147483647, 2147483647]
  219 |  sprintf(s, "(%d)", e->lastMission + 1);
      |             ^~~~~~
In file included from /usr/include/stdio.h:867,
                 from src/json/json.h:31,
                 from src/cdogs/cpic.h:30,
                 from src/cdogs/character_class.h:31,
                 from src/cdogs/character.h:32,
                 from src/cdogs/campaigns.h:33,
                 from src/hiscores.h:51,
                 from src/hiscores.c:49:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 4 and 14 bytes into a destination of size 10
   36 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |       __bos (__s), __fmt, __va_arg_pack ());
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[12/208] Building C object src/CMakeFiles/cdogs-sdl.dir/namegen.c.o
FAILED: src/CMakeFiles/cdogs-sdl.dir/namegen.c.o 
/usr/bin/ccache /usr/bin/cc -DNDEBUG -DPB_FIELD_16BIT -Isrc/cdogs/enet/include -Isrc/cdogs/proto/nanopb -Isrc -Isrc/cdogs -Isrc/. -I/usr/include/x86_64-linux-gnu/SDL2 -I/usr/include/SDL2 -O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection   -fsigned-char -Wall -W -Wstrict-prototypes -Wpointer-arith -Wcast-qual -O2 -freg-struct-return -std=gnu99 -Wshadow -Wimplicit-fallthrough=0 -Wno-error=format-overflow -Winline -Werror -MD -MT src/CMakeFiles/cdogs-sdl.dir/namegen.c.o -MF src/CMakeFiles/cdogs-sdl.dir/namegen.c.o.d -o src/CMakeFiles/cdogs-sdl.dir/namegen.c.o   -c src/namegen.c
In file included from /usr/include/string.h:494,
                 from src/namegen.c:31:
In function ‘strncpy’,
    inlined from ‘LoadFile’ at src/namegen.c:53:3:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/namegen.c: In function ‘LoadFile’:
src/namegen.c:53:21: note: length computed here
   53 |   strncpy(str, buf, strlen(buf) - 1);
      |                     ^~~~~~~~~~~
cc1: all warnings being treated as errors
[13/208] Building C object src/CMakeFiles/cdogs-sdl.dir/menu_utils.c.o
src/menu_utils.c: In function ‘MenuDisplayPlayerControls’:
src/menu_utils.c:108:18: warning: ‘ to scroll,
left and right c...’ directive writing 33 bytes into a region of size between 0 and 255 [-Wformat-overflow=]
  108 |   sprintf(s, "(%s to scroll,\nleft and right click)", directionNames);
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/stdio.h:867,
                 from src/json/json.h:31,
                 from src/cdogs/cpic.h:30,
                 from src/cdogs/character_class.h:31,
                 from src/cdogs/character.h:32,
                 from src/menu_utils.h:31,
                 from src/menu_utils.c:29:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 35 and 290 bytes into a destination of size 256
   36 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |       __bos (__s), __fmt, __va_arg_pack ());
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/menu_utils.c:103:19: warning: ‘,
   ’ directive writing 2 bytes into a region of size between 0 and 255 [-Wformat-overflow=]
  103 |    sprintf(s, "(%s,\n%s and %s)", directionNames, button1, button2);
      |                   ^~~
In file included from /usr/include/stdio.h:867,
                 from src/json/json.h:31,
                 from src/cdogs/cpic.h:30,
                 from src/cdogs/character_class.h:31,
                 from src/cdogs/character.h:32,
                 from src/menu_utils.h:31,
                 from src/menu_utils.c:29:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 10 and 775 bytes into a destination of size 256
   36 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |       __bos (__s), __fmt, __va_arg_pack ());
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cxong commented 4 years ago

should be fixed now - I've set up travis to use gcc 9 and it builds with no errors