aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/grep/grep.c
diff options
context:
space:
mode:
authorGabor Kovesdan <gabor@FreeBSD.org>2011-08-17 13:56:33 +0000
committerGabor Kovesdan <gabor@FreeBSD.org>2011-08-17 13:56:33 +0000
commitdab19f3084733e6d685609120d915c7cd9e5cd51 (patch)
treef0b8dddc3cbaf2ef0b7699f444666e2a676926f3 /usr.bin/grep/grep.c
parenta6bab2362ea6963901884bf0929c54a001e79d8b (diff)
downloadsrc-dab19f3084733e6d685609120d915c7cd9e5cd51.tar.gz
src-dab19f3084733e6d685609120d915c7cd9e5cd51.zip
- Fix handling of environmental variables when they are set to empty string
Submitted by: ttsestt@gmail.com Approved by: re (kib), delphij (mentor)
Notes
Notes: svn path=/head/; revision=224937
Diffstat (limited to 'usr.bin/grep/grep.c')
-rw-r--r--usr.bin/grep/grep.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c
index d03c13c7713f..73e1d3d3371f 100644
--- a/usr.bin/grep/grep.c
+++ b/usr.bin/grep/grep.c
@@ -304,7 +304,7 @@ init_color(const char *d)
char *c;
c = getenv("GREP_COLOR");
- return (c != NULL ? c : d);
+ return (c != NULL && c[0] != '\0' ? c : d);
}
int
@@ -360,7 +360,7 @@ main(int argc, char *argv[])
/* support for extra arguments in GREP_OPTIONS */
eargc = 0;
- if (eopts != NULL) {
+ if (eopts != NULL && eopts[0] != '\0') {
char *str;
/* make an estimation of how many extra arguments we have */
@@ -373,7 +373,8 @@ main(int argc, char *argv[])
eargc = 0;
/* parse extra arguments */
while ((str = strsep(&eopts, " ")) != NULL)
- eargv[eargc++] = grep_strdup(str);
+ if (str[0] != '\0')
+ eargv[eargc++] = grep_strdup(str);
aargv = (char **)grep_calloc(eargc + argc + 1,
sizeof(char *));