grep: fix echo "aa" | busybox grep -F -w "a" (should not match)
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 29 Mar 2018 16:03:50 +0000 (18:03 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 29 Mar 2018 16:03:50 +0000 (18:03 +0200)
function                                             old     new   delta
grep_file                                           1461    1470      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
findutils/grep.c
testsuite/grep.tests

index fc6de4b69775ee5b6a9b74a13a33e313a80b7899..88de0d4ef18c6e18037e1465db0ee0e7c294034f 100644 (file)
@@ -352,7 +352,7 @@ static int grep_file(FILE *file)
                                                        goto opt_f_not_found;
                                        } else
                                        if (option_mask32 & OPT_w) {
-                                               char c = (match != str) ? match[-1] : ' ';
+                                               char c = (match != line) ? match[-1] : ' ';
                                                if (!isalnum(c) && c != '_') {
                                                        c = match[strlen(gl->pattern)];
                                                        if (!c || (!isalnum(c) && c != '_'))
index ed4ba455eb84ccb9a6135c11b3bd9e80c193ebdb..d0b0d2767cb26a4818b2979e9282a1f06c413a69 100755 (executable)
@@ -165,6 +165,12 @@ testing "grep -w word doesn't match wordword" \
        "wordword\n" \
        ""
 
+testing "grep -F -w w doesn't match ww" \
+       "grep -F -w w input" \
+       "" \
+       "ww\n" \
+       ""
+
 testing "grep -w word match second word" \
        "grep -w word input" \
        "bword,word\n""wordb,word\n""bwordb,word\n" \