]> granicus.if.org Git - procps-ng/commitdiff
pgrep: Fix off by one error in line check
authorCraig Small <csmall@enc.com.au>
Sun, 11 Sep 2016 00:11:25 +0000 (10:11 +1000)
committerCraig Small <csmall@enc.com.au>
Sun, 11 Sep 2016 00:11:25 +0000 (10:11 +1000)
There is now a warning if your command is longer than 15 characters
and therefore can never match. Except it was checking for more than
16 characters.

Adjusted this and added a test case.

References:
 !25
 commit 8e8835b2ee4af7947d5131895ef1719129d3e70d

pgrep.c
testsuite/pgrep.test/pgrep.exp

diff --git a/pgrep.c b/pgrep.c
index c9bc36e8658e469d72704ecda169911105877c2b..6708f87a39e1ce7634c1761df9f700ff034193ed 100644 (file)
--- a/pgrep.c
+++ b/pgrep.c
@@ -888,7 +888,7 @@ static void parse_opts (int argc, char **argv)
        if (argc - optind == 1)
        {
                opt_pattern = argv[optind];
-               if ((!opt_full) && (strlen(opt_pattern) > 16))
+               if ((!opt_full) && (strlen(opt_pattern) > 15))
                        xwarnx(_("pattern that contains program name longer than 15 characters will result in zero matches\n"
                                         "Try `%s -f' option for thorough search."),
                                         program_invocation_short_name);
index ef2678357a18112701218282d5bb8678f361a304..493d1a5548d5025f093152948b451ca0f3e396fa 100644 (file)
@@ -118,6 +118,9 @@ set test "pgrep does not match substring with exact"
 spawn $pgrep -x $testproc_trim
 expect_blank $test
 
+set test "pgrep with long match gives warning"
+spawn $pgrep gnome-session-bi
+expect_pass "$test" "pattern that contains program name longer than 15 characters will result in zero matches"
 
 # Cleanup
 kill_testproc