@@ -16,7 +16,8 @@ FILE *init_state_files() {
1616 char * username = getenv ("USER" );
1717 if (strcmp (username , "root" ) == 0 ) {
1818 printf ("Please enter your username ($USER): " );
19- scanf ("%s[^\n]" , username_n );
19+ while (scanf ("%s[^\n]" , username_n ) != 1 )
20+ ;
2021 username = username_n ;
2122 }
2223 char save_path [strlen (save_directory ) + strlen (username ) + 5 ];
@@ -150,9 +151,12 @@ char **userHighscores2string(UserHighscore *highscores) {
150151 char time [32 ];
151152 struct tm * local_time = localtime (& highscores [index ].highscore .date );
152153 strftime (time , 32 , "%Y-%m-%d" , local_time );
153- asprintf (& tmp , " %02u:%02u %s %s " , highscores [index ].highscore .time / 60 ,
154- highscores [index ].highscore .time % 60 , time ,
155- highscores [index ].user );
154+ if (asprintf (& tmp , " %02u:%02u %s %s " ,
155+ highscores [index ].highscore .time / 60 ,
156+ highscores [index ].highscore .time % 60 , time ,
157+ highscores [index ].user ) == -1 )
158+ exit (EXIT_FAILURE );
159+
156160 if (tmp == NULL )
157161 exit (EXIT_FAILURE );
158162 free (highscores [index ].user );
0 commit comments