Skip to content

Commit

Permalink
examples/playmus: Prevent stack smashing on long input strings
Browse files Browse the repository at this point in the history
In addition, fflush(stdin) is undefined behaviour, so remove it.

(cherry picked from commit ef53736)
(cherry picked from commit 8a0af85)
  • Loading branch information
tatokis authored and slouken committed Feb 25, 2024
1 parent 5bcd40a commit 8508777
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions playmus.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ void Menu(void)
char buf[10];

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

0 comments on commit 8508777

Please sign in to comment.