]> granicus.if.org Git - nethack/commitdiff
resolve a warning in sounds.c
authornhmall <nhmall@nethack.org>
Tue, 2 Feb 2021 01:02:12 +0000 (20:02 -0500)
committernhmall <nhmall@nethack.org>
Tue, 2 Feb 2021 01:02:12 +0000 (20:02 -0500)
sounds.c: In function ‘add_sound_mapping’:
sounds.c:1381:33: warning: ‘sprintf’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
 1381 |         Sprintf(filespec, "%s/%s", sounddir, filename);
      |                                 ^
In file included from ../include/config.h:631,
                 from ../include/hack.h:10,
                 from sounds.c:5:
../include/global.h:274:24: note: ‘sprintf’ output 2 or more bytes (assuming 257) into a destination of size 256
  274 | #define Sprintf (void) sprintf
sounds.c:1381:9: note: in expansion of macro ‘Sprintf’
 1381 |         Sprintf(filespec, "%s/%s", sounddir, filename);
      |         ^~~~~~~

src/sounds.c

index d6df797bbbac2743091ac9a6749e181b495ad020..a43ecb402dd31641be799cd62e48d2223fc39481 100644 (file)
@@ -1378,7 +1378,7 @@ add_sound_mapping(const char* mapping)
             raw_print("sound file name too long");
             return 0;
        }
-        Sprintf(filespec, "%s/%s", sounddir, filename);
+        Snprintf(filespec, sizeof filespec, "%s/%s", sounddir, filename);
 
         if (idx >= 0 || can_read_file(filespec)) {
             new_map = (audio_mapping *) alloc(sizeof *new_map);