Skip to content

Commit 8508777

Browse files
tatokisslouken
authored andcommitted
examples/playmus: Prevent stack smashing on long input strings
In addition, fflush(stdin) is undefined behaviour, so remove it. (cherry picked from commit ef53736) (cherry picked from commit 8a0af85)
1 parent 5bcd40a commit 8508777

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

playmus.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ void Menu(void)
7373
char buf[10];
7474

7575
printf("Available commands: (p)ause (r)esume (h)alt volume(v#) > ");
76-
fflush(stdin);
77-
if (scanf("%s",buf) == 1) {
76+
if (fgets(buf, sizeof(buf), stdin)) {
7877
switch(buf[0]) {
7978
#if defined(SEEK_TEST)
8079
case '0': Mix_SetMusicPosition(0); break;

0 commit comments

Comments
 (0)