From owner-p4-projects@FreeBSD.ORG Tue Jun 17 12:38:08 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 7F2BA106567F; Tue, 17 Jun 2008 12:38:08 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 40D9D1065670 for ; Tue, 17 Jun 2008 12:38:08 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 2CE388FC29 for ; Tue, 17 Jun 2008 12:38:08 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m5HCc8Jc030335 for ; Tue, 17 Jun 2008 12:38:08 GMT (envelope-from gabor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m5HCc8qO030333 for perforce@freebsd.org; Tue, 17 Jun 2008 12:38:08 GMT (envelope-from gabor@freebsd.org) Date: Tue, 17 Jun 2008 12:38:08 GMT Message-Id: <200806171238.m5HCc8qO030333@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gabor@freebsd.org using -f From: Gabor Kovesdan To: Perforce Change Reviews Cc: Subject: PERFORCE change 143639 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Jun 2008 12:38:08 -0000 http://perforce.freebsd.org/chv.cgi?CH=143639 Change 143639 by gabor@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);