Use sizeof() for calculating the buffer size instead of hard-coded values.

This commit is contained in:
Kevin Lo 2007-03-06 09:32:41 +00:00
parent a9093e846d
commit d069140339
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=167260
8 changed files with 9 additions and 9 deletions

View File

@ -224,7 +224,7 @@ file(char *name)
args[3] = &arg[3][0];
args[4] = &arg[4][0];
retval = 0;
while(fgets(line, 100, fp) != NULL) {
while(fgets(line, sizeof(line), fp) != NULL) {
if ((p = strchr(line, '#')) != NULL)
*p = '\0';
for (p = line; isblank(*p); p++);

View File

@ -191,7 +191,7 @@ void add_file_to_keep_list(char *filename)
usage();
}
while(fgets(symbol, 1024, keepf)) {
while(fgets(symbol, sizeof(symbol), keepf)) {
len = strlen(symbol);
if(len && symbol[len-1] == '\n')
symbol[len-1] = '\0';

View File

@ -382,7 +382,7 @@ show_dialog(struct keymap **km_sorted, int num_keymaps)
fp = fopen(tmp_name, "r");
if (fp) {
char choice[64];
if (fgets(choice, 64, fp) != NULL) {
if (fgets(choice, sizeof(choice), fp) != NULL) {
/* Find key for desc */
for (i=0; i<num_keymaps; i++) {
if (!strcmp(choice, km_sorted[i]->desc)) {

View File

@ -351,7 +351,7 @@ read_number(const char *fn)
if ((fp = fopen(fn, "r")) == NULL)
return (0);
if (fgets(lin, 80, fp) == NULL) {
if (fgets(lin, sizeof(lin), fp) == NULL) {
fclose(fp);
return (0);
}

View File

@ -39,7 +39,7 @@ main( argc, argv )
printf( "multicast membership test program; " );
printf( "enter ? for list of commands\n" );
while( fgets( line, 79, stdin ) != NULL )
while( fgets( line, sizeof(line) - 1, stdin ) != NULL )
{
lineptr = line;
while( *lineptr == ' ' || *lineptr == '\t' ) ++lineptr;

View File

@ -333,7 +333,7 @@ file(name)
args[3] = &arg[3][0];
args[4] = &arg[4][0];
retval = 0;
while (fgets(line, 100, fp) != NULL) {
while (fgets(line, sizeof(line), fp) != NULL) {
i = sscanf(line, "%49s %49s %49s %49s %49s",
arg[0], arg[1], arg[2], arg[3], arg[4]);
if (i < 2) {

View File

@ -30,7 +30,7 @@ prompt_term(char **termp)
printf("\nPlease set your TERM variable before running this program.\n");
printf("Defaulting to an ANSI compatible terminal - please press RETURN\n");
fgets(str, 80, stdin); /* Just to make it interactive */
fgets(str, sizeof(str), stdin); /* Just to make it interactive */
*termp = (char *)"ansi";
}

View File

@ -50,7 +50,7 @@ prompt_term(char **termp, char **termcapp)
printf("5 ...................... xterm terminal emulator.\n\n");
printf("Your choice: (1-5) ");
fflush(stdout);
fgets(str, 80, stdin);
fgets(str, sizeof(str), stdin);
i = str[0] - '0';
if (i > 0 && i < 6) {
*termp = (char *)lookup[i - 1].term;
@ -64,7 +64,7 @@ prompt_term(char **termp, char **termcapp)
else {
printf("\nPlease set your TERM variable before running this program.\n");
printf("Defaulting to an ANSI compatible terminal - please press RETURN\n");
fgets(str, 80, stdin); /* Just to make it interactive */
fgets(str, sizeof(str), stdin); /* Just to make it interactive */
*termp = (char *)"ansi";
*termcapp = (char *)termcap_ansi;
}