diff --git a/src/drivers/common/cheat.cpp b/src/drivers/common/cheat.cpp index e6803f9d..2e54a1eb 100644 --- a/src/drivers/common/cheat.cpp +++ b/src/drivers/common/cheat.cpp @@ -26,7 +26,11 @@ static void GetString(char *s, int max) { int x; - fgets(s,max,stdin); + if ( fgets(s,max,stdin) == nullptr ) + { + s[0] = 0; + return; + } for(x=0;x "); - fgets(buf,ARRAY_SIZE(buf),stdin); + if ( fgets(buf,ARRAY_SIZE(buf),stdin) == nullptr ) + { + return -1; + } if(buf[0]=='s' || buf[0]=='S') return(-1); if(buf[0]=='\n') return(0); if(!sscanf(buf,"%d",&num)) @@ -128,7 +147,10 @@ int ListChoice(int hmm) tryagain2: printf(" <'Enter' to make no selection or enter a number.> "); - fgets(buf,ARRAY_SIZE(buf),stdin); + if ( fgets(buf,ARRAY_SIZE(buf),stdin) == nullptr ) + { + return -1; + } if(buf[0]=='\n') return(0); if(!sscanf(buf,"%d",&num)) return(0); @@ -349,7 +371,10 @@ static void ListCheats(void) { char tmp[32]; printf(" <(T)oggle status, (M)odify, or (D)elete this cheat.> "); - fgets(tmp,ARRAY_SIZE(tmp),stdin); + if ( fgets(tmp,ARRAY_SIZE(tmp),stdin) == nullptr ) + { + tmp[0] = 0; + } switch(tolower(tmp[0])) { case 't':ToggleCheat(which); @@ -406,7 +431,10 @@ static int ShowShortList(const char *moe[], int n, int def) clo: printf("\nSelection [%d]> ",def+1); - fgets(tmp,ARRAY_SIZE(tmp),stdin); + if ( fgets(tmp,ARRAY_SIZE(tmp),stdin) == nullptr ) + { + return def; + } if(tmp[0]=='\n') return def; c=tolower(tmp[0]); @@ -505,7 +533,10 @@ static void DoMenu(MENU *men) recommand: printf("Command> "); - fgets(buf,ARRAY_SIZE(buf),stdin); + if ( fgets(buf,ARRAY_SIZE(buf),stdin) == nullptr ) + { + return; + } c=tolower(buf[0]); if(c=='\n') goto recommand;