stephenjsweeney/tbftss

Build fails in setLanguage

Closed this issue · 2 comments

I'm using the the source for version 1.4.0, on linux, with gcc 8.2.1 and the build fails with the following errors:

gcc -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt `sdl2-config --cflags` -DVERSION=1.4 -DREVISION=0 -DDATA_DIR=\"/opt/tbftss\" -DLOCALE_DIR=\"/usr/share/locale\" -Wall -Wempty-body -ansi -pedantic -Werror -Wstrict-prototypes -Werror=maybe-uninitialized -Warray-bounds -g -lefence -c -o bin/i18n.o src/system/i18n.c
src/system/i18n.c: In function ‘setLanguage’:
src/system/i18n.c:79:17: error: ‘%s’ directive writing up to 1023 bytes into a region of size 1006 [-Werror=format-overflow=]
  sprintf(c, "%s/%s/LC_MESSAGES/%s.mo", LOCALE_DIR, language, applicationName);
                 ^~                                 ~~~~~~~~
src/system/i18n.c:79:2: note: ‘sprintf’ output 35 or more bytes (assuming 1058) into a destination of size 1024
  sprintf(c, "%s/%s/LC_MESSAGES/%s.mo", LOCALE_DIR, language, applicationName);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/system/i18n.c:100:18: error: ‘%s’ directive writing up to 1023 bytes into a region of size 1006 [-Werror=format-overflow=]
   sprintf(c, "%s/%s/LC_MESSAGES/%s.mo", LOCALE_DIR, language, applicationName);
                  ^~                                 ~~~~~~~~
src/system/i18n.c:100:3: note: ‘sprintf’ output 35 or more bytes (assuming 1058) into a destination of size 1024
   sprintf(c, "%s/%s/LC_MESSAGES/%s.mo", LOCALE_DIR, language, applicationName);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/system/../common.h:29,
                 from src/system/i18n.h:20,
                 from src/system/i18n.c:20:
In function ‘put’,
    inlined from ‘setLanguage’ at src/system/i18n.c:223:3:
src/system/../defs.h:38:31: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
 #define STRNCPY(dest, src, n) strncpy(dest, src, n); dest[n - 1] = '\0'
                               ^~~~~~~~~~~~~~~~~~~~~
src/system/i18n.c:330:2: note: in expansion of macro ‘STRNCPY’
  STRNCPY(newBucket->key, key, strlen(key) + 1);
  ^~~~~~~
src/system/i18n.c: In function ‘setLanguage’:
src/system/i18n.c:330:31: note: length computed here
  STRNCPY(newBucket->key, key, strlen(key) + 1);
                               ^~~~~~~~~~~
src/system/../defs.h:38:50: note: in definition of macro ‘STRNCPY’
 #define STRNCPY(dest, src, n) strncpy(dest, src, n); dest[n - 1] = '\0'
                                                  ^
In function ‘put’,
    inlined from ‘setLanguage’ at src/system/i18n.c:223:3:
src/system/../defs.h:38:31: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
 #define STRNCPY(dest, src, n) strncpy(dest, src, n); dest[n - 1] = '\0'
                               ^~~~~~~~~~~~~~~~~~~~~
src/system/i18n.c:331:2: note: in expansion of macro ‘STRNCPY’
  STRNCPY(newBucket->value, value, strlen(value) + 1);
  ^~~~~~~
src/system/i18n.c: In function ‘setLanguage’:
src/system/i18n.c:331:35: note: length computed here
  STRNCPY(newBucket->value, value, strlen(value) + 1);
                                   ^~~~~~~~~~~~~
src/system/../defs.h:38:50: note: in definition of macro ‘STRNCPY’
 #define STRNCPY(dest, src, n) strncpy(dest, src, n); dest[n - 1] = '\0'
                                                  ^
cc1: all warnings being treated as errors
make: *** [common.mk:42: bin/i18n.o] Error 1

Is this maybe related to #16 (comment) ?

Could you try building from the develop branch? Should be version 1.4.3.

Okay, so I tried the git develop branch directly, and this time, it built successfully, and only with warnings instead of errors. Also, the game is playable. Yay!

gcc -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt `sdl2-config --cflags` -DVERSION=1.4 -DREVISION=3 -DDATA_DIR=\"/opt/tbftss\" -DLOCALE_DIR=\"/usr/share/locale\" -ansi -pedantic -g -lefence -c -o bin/i18n.o src/system/i18n.c
In file included from src/system/../common.h:29,
                 from src/system/i18n.h:20,
                 from src/system/i18n.c:20:
In function ‘put’,
    inlined from ‘setLanguage’ at src/system/i18n.c:231:3:
src/system/../defs.h:54:31: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
 #define STRNCPY(dest, src, n) strncpy(dest, src, n); dest[n - 1] = '\0'
                               ^~~~~~~~~~~~~~~~~~~~~
src/system/i18n.c:338:2: note: in expansion of macro ‘STRNCPY’
  STRNCPY(newBucket->key, key, strlen(key) + 1);
  ^~~~~~~
src/system/i18n.c: In function ‘setLanguage’:
src/system/i18n.c:338:31: note: length computed here
  STRNCPY(newBucket->key, key, strlen(key) + 1);
                               ^~~~~~~~~~~
src/system/../defs.h:54:50: note: in definition of macro ‘STRNCPY’
 #define STRNCPY(dest, src, n) strncpy(dest, src, n); dest[n - 1] = '\0'
                                                  ^
In function ‘put’,
    inlined from ‘setLanguage’ at src/system/i18n.c:231:3:
src/system/../defs.h:54:31: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
 #define STRNCPY(dest, src, n) strncpy(dest, src, n); dest[n - 1] = '\0'
                               ^~~~~~~~~~~~~~~~~~~~~
src/system/i18n.c:339:2: note: in expansion of macro ‘STRNCPY’
  STRNCPY(newBucket->value, value, strlen(value) + 1);
  ^~~~~~~
src/system/i18n.c: In function ‘setLanguage’:
src/system/i18n.c:339:35: note: length computed here
  STRNCPY(newBucket->value, value, strlen(value) + 1);
                                   ^~~~~~~~~~~~~
src/system/../defs.h:54:50: note: in definition of macro ‘STRNCPY’
 #define STRNCPY(dest, src, n) strncpy(dest, src, n); dest[n - 1] = '\0'
                                                  ^

and separately:

gcc -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt `sdl2-config --cflags` -DVERSION=1.4 -DREVISION=3 -DDATA_DIR=\"/opt/tbftss\" -DLOCALE_DIR=\"/usr/share/locale\" -ansi -pedantic -g -lefence -c -o bin/lookup.o src/system/lookup.c
In file included from src/system/../common.h:29,
                 from src/system/lookup.h:21,
                 from src/system/lookup.c:21:
src/system/lookup.c: In function ‘flagsToLong’:
src/system/../defs.h:54:31: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
 #define STRNCPY(dest, src, n) strncpy(dest, src, n); dest[n - 1] = '\0'
                               ^~~~~~~~~~~~~~~~~~~~~
src/system/lookup.c:273:2: note: in expansion of macro ‘STRNCPY’
  STRNCPY(flags, in, strlen(in) + 1);
  ^~~~~~~
src/system/lookup.c:273:21: note: length computed here
  STRNCPY(flags, in, strlen(in) + 1);
                     ^~~~~~~~~~
src/system/../defs.h:54:50: note: in definition of macro ‘STRNCPY’
 #define STRNCPY(dest, src, n) strncpy(dest, src, n); dest[n - 1] = '\0'
                                                  ^