use ARRAY_SIZE macro rather than fixing buffer size forfgets

This commit is contained in:
qeed 2010-09-03 16:38:20 +00:00
parent b8e439ac46
commit 0666741d55
1 changed files with 10 additions and 9 deletions

View File

@ -21,6 +21,7 @@
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include "../../driver.h" #include "../../driver.h"
#include "../../fceu.h"
static void GetString(char *s, int max) static void GetString(char *s, int max)
{ {
@ -40,7 +41,7 @@ static uint32 GetH16(unsigned int def)
{ {
char buf[32]; char buf[32];
fgets(buf,32,stdin); fgets(buf,ARRAY_SIZE(buf),stdin);
if(buf[0]=='\n') if(buf[0]=='\n')
return(def); return(def);
if(buf[0]=='$') if(buf[0]=='$')
@ -55,7 +56,7 @@ static uint8 Get8(unsigned int def)
{ {
char buf[32]; char buf[32];
fgets(buf,32,stdin); fgets(buf,ARRAY_SIZE(buf),stdin);
if(buf[0]=='\n') if(buf[0]=='\n')
return(def); return(def);
sscanf(buf,"%u",&def); sscanf(buf,"%u",&def);
@ -66,7 +67,7 @@ static int GetI(int def)
{ {
char buf[32]; char buf[32];
fgets(buf,32,stdin); fgets(buf,ARRAY_SIZE(buf),stdin);
if(buf[0]=='\n') if(buf[0]=='\n')
return(def); return(def);
sscanf(buf,"%d",&def); sscanf(buf,"%d",&def);
@ -77,7 +78,7 @@ 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,32,stdin); fgets(buf,ARRAY_SIZE(buf),stdin);
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')
@ -113,7 +114,7 @@ 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,32,stdin); fgets(buf,ARRAY_SIZE(buf),stdin);
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))
@ -127,7 +128,7 @@ 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,32,stdin); fgets(buf,ARRAY_SIZE(buf),stdin);
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);
@ -347,7 +348,7 @@ 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,32,stdin); fgets(tmp,ARRAY_SIZE(buf),stdin);
switch(tolower(tmp[0])) switch(tolower(tmp[0]))
{ {
case 't':ToggleCheat(which); case 't':ToggleCheat(which);
@ -404,7 +405,7 @@ static int ShowShortList(char *moe[], int n, int def)
clo: clo:
printf("\nSelection [%d]> ",def+1); printf("\nSelection [%d]> ",def+1);
fgets(tmp,256,stdin); fgets(tmp,ARRAY_SIZE(buf),stdin);
if(tmp[0]=='\n') if(tmp[0]=='\n')
return def; return def;
c=tolower(tmp[0]); c=tolower(tmp[0]);
@ -481,7 +482,7 @@ static void DoMenu(MENU *men)
recommand: recommand:
printf("Command> "); printf("Command> ");
fgets(buf,32,stdin); fgets(buf,ARRAY_SIZE(buf),stdin);
c=tolower(buf[0]); c=tolower(buf[0]);
if(c=='\n') if(c=='\n')
goto recommand; goto recommand;