Convert strdup call to xstrdup, and calloc calls to xcalloc (patch from

Steve Merrifield).
This commit is contained in:
Matt Kraai 2001-11-12 16:58:07 +00:00
parent c8227639db
commit a21c24bf03

View File

@ -155,7 +155,7 @@ static void grep_file(FILE *file)
if(lines_before) { if(lines_before) {
if(before_buf[curpos]) if(before_buf[curpos])
free(before_buf[curpos]); free(before_buf[curpos]);
before_buf[curpos] = strdup(line); before_buf[curpos] = xstrdup(line);
curpos = (curpos + 1) % lines_before; curpos = (curpos + 1) % lines_before;
} }
} }
@ -306,13 +306,13 @@ extern int grep_main(int argc, char **argv)
lines_before = strtoul(optarg, &junk, 10); lines_before = strtoul(optarg, &junk, 10);
if(*junk != '\0') if(*junk != '\0')
error_msg_and_die("invalid context length argument"); error_msg_and_die("invalid context length argument");
before_buf = (char **)calloc(lines_before, sizeof(char *)); before_buf = (char **)xcalloc(lines_before, sizeof(char *));
break; break;
case 'C': case 'C':
lines_after = lines_before = strtoul(optarg, &junk, 10); lines_after = lines_before = strtoul(optarg, &junk, 10);
if(*junk != '\0') if(*junk != '\0')
error_msg_and_die("invalid context length argument"); error_msg_and_die("invalid context length argument");
before_buf = (char **)calloc(lines_before, sizeof(char *)); before_buf = (char **)xcalloc(lines_before, sizeof(char *));
break; break;
#endif /* CONFIG_FEATURE_GREP_CONTEXT */ #endif /* CONFIG_FEATURE_GREP_CONTEXT */
default: default: