From: nhmall Date: Tue, 2 Feb 2021 01:02:12 +0000 (-0500) Subject: resolve a warning in sounds.c X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=13394d12e5f1b913908267ae4247429d6be3af72;p=nethack resolve a warning in sounds.c 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); | ^~~~~~~ --- diff --git a/src/sounds.c b/src/sounds.c index d6df797bb..a43ecb402 100644 --- a/src/sounds.c +++ b/src/sounds.c @@ -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);