Cleaned up -Wunused-result warnings for usage of fgets. fgets from stdin should really never fail so just added nullptr return handling to silence warning.

This commit is contained in:
harry 2023-01-29 11:42:32 -05:00
parent 421c7b35e7
commit 4944faf618
1 changed files with 41 additions and 10 deletions

View File

@ -26,7 +26,11 @@
static void GetString(char *s, int max) static void GetString(char *s, int max)
{ {
int x; int x;
fgets(s,max,stdin); if ( fgets(s,max,stdin) == nullptr )
{
s[0] = 0;
return;
}
for(x=0;x<max;x++) for(x=0;x<max;x++)
if(s[x]=='\n') if(s[x]=='\n')
@ -41,7 +45,10 @@ static uint32 GetH16(unsigned int def)
{ {
char buf[32]; char buf[32];
fgets(buf,ARRAY_SIZE(buf),stdin); if ( fgets(buf,ARRAY_SIZE(buf),stdin) == nullptr )
{
return def;
}
if(buf[0]=='\n') if(buf[0]=='\n')
return(def); return(def);
if(buf[0]=='$') if(buf[0]=='$')
@ -56,7 +63,10 @@ static uint8 Get8(unsigned int def)
{ {
char buf[32]; char buf[32];
fgets(buf,ARRAY_SIZE(buf),stdin); if ( fgets(buf,ARRAY_SIZE(buf),stdin) == nullptr )
{
return def;
}
if(buf[0]=='\n') if(buf[0]=='\n')
return(def); return(def);
sscanf(buf,"%u",&def); sscanf(buf,"%u",&def);
@ -67,7 +77,10 @@ static int GetI(int def)
{ {
char buf[32]; char buf[32];
fgets(buf,ARRAY_SIZE(buf),stdin); if ( fgets(buf,ARRAY_SIZE(buf),stdin) == nullptr )
{
return def;
}
if(buf[0]=='\n') if(buf[0]=='\n')
return(def); return(def);
sscanf(buf,"%d",&def); sscanf(buf,"%d",&def);
@ -78,7 +91,10 @@ static int GetYN(int def)
{ {
char buf[32]; char buf[32];
printf("(Y/N)[%s]: ",def?"Y":"N"); printf("(Y/N)[%s]: ",def?"Y":"N");
fgets(buf,ARRAY_SIZE(buf),stdin); if ( fgets(buf,ARRAY_SIZE(buf),stdin) == nullptr )
{
return def;
}
if(buf[0]=='y' || buf[0]=='Y') if(buf[0]=='y' || buf[0]=='Y')
return(1); return(1);
if(buf[0]=='n' || buf[0]=='N') if(buf[0]=='n' || buf[0]=='N')
@ -114,7 +130,10 @@ int ListChoice(int hmm)
tryagain: tryagain:
printf(" <'Enter' to continue, (S)top, or enter a number.> "); printf(" <'Enter' to continue, (S)top, or enter a number.> ");
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]=='s' || buf[0]=='S') return(-1);
if(buf[0]=='\n') return(0); if(buf[0]=='\n') return(0);
if(!sscanf(buf,"%d",&num)) if(!sscanf(buf,"%d",&num))
@ -128,7 +147,10 @@ int ListChoice(int hmm)
tryagain2: tryagain2:
printf(" <'Enter' to make no selection or enter a number.> "); 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(buf[0]=='\n') return(0);
if(!sscanf(buf,"%d",&num)) if(!sscanf(buf,"%d",&num))
return(0); return(0);
@ -349,7 +371,10 @@ static void ListCheats(void)
{ {
char tmp[32]; char tmp[32];
printf(" <(T)oggle status, (M)odify, or (D)elete this cheat.> "); 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])) switch(tolower(tmp[0]))
{ {
case 't':ToggleCheat(which); case 't':ToggleCheat(which);
@ -406,7 +431,10 @@ static int ShowShortList(const char *moe[], int n, int def)
clo: clo:
printf("\nSelection [%d]> ",def+1); 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') if(tmp[0]=='\n')
return def; return def;
c=tolower(tmp[0]); c=tolower(tmp[0]);
@ -505,7 +533,10 @@ static void DoMenu(MENU *men)
recommand: recommand:
printf("Command> "); printf("Command> ");
fgets(buf,ARRAY_SIZE(buf),stdin); if ( fgets(buf,ARRAY_SIZE(buf),stdin) == nullptr )
{
return;
}
c=tolower(buf[0]); c=tolower(buf[0]);
if(c=='\n') if(c=='\n')
goto recommand; goto recommand;