PERFORCE change 143639 for review
Gabor Kovesdan
gabor at FreeBSD.org
Tue Jun 17 12:38:08 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=143639
Change 143639 by gabor at gabor_server on 2008/06/17 12:37:14
- Clean up allocations
- Improve --color compatibility
Affected files ...
.. //depot/projects/soc2008/gabor_textproc/grep/grep.c#20 edit
.. //depot/projects/soc2008/gabor_textproc/grep/util.c#21 edit
Differences ...
==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#20 (text+ko) ====
@@ -455,14 +455,14 @@
case COLOR_OPT:
if (optarg == NULL)
optarg = "auto";
- if (strcmp("always", optarg) == 0) {
+ if (strcmp("auto", optarg) == 0 || strcmp("always", optarg) == 0 ) {
color = getenv("GREP_COLOR");
if (color == NULL)
color = "01;31";
- } else if ((strcmp("auto", optarg) == 0))
- color = getenv("GREP_COLOR");
- else if (strcmp("never", optarg) == 0)
+ } else if (strcmp("never", optarg) == 0)
color = NULL;
+ else
+ usage();
break;
case LABEL_OPT:
label = optarg;
==== //depot/projects/soc2008/gabor_textproc/grep/util.c#21 (text+ko) ====
@@ -227,11 +227,11 @@
if ((r == 0) && (color != NULL) && !oflag && !nottext) {
char *tmp, *begin, *matched, *end;
- if ((begin = malloc(strlen(l->dat) - pmatch.rm_so + 20)) == NULL)
+ if ((begin = malloc(strlen(l->dat) - pmatch.rm_so + 1)) == NULL)
errx(2, NULL);
- if ((matched = malloc((pmatch.rm_eo - pmatch.rm_so + 20) * sizeof(char))) == NULL)
+ if ((matched = malloc((pmatch.rm_eo - pmatch.rm_so + 1) * sizeof(char))) == NULL)
errx(2, NULL);
- if ((end = malloc(strlen(l->dat) - pmatch.rm_eo + 20)) == NULL)
+ if ((end = malloc(strlen(l->dat) - pmatch.rm_eo + 1)) == NULL)
errx(2, NULL);
strlcpy(begin, l->dat, pmatch.rm_so + 1);
More information about the p4-projects
mailing list