bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/4] tests: add a case to exercise one more block in match_mb_cha


From: Jim Meyering
Subject: [PATCH 4/4] tests: add a case to exercise one more block in match_mb_charset
Date: Sat, 14 Apr 2012 11:40:07 +0200

Noticing the few remaining uses of strncpy in dfa.c,
I thought they too should be converted to use memcpy or related.
I.e., what if the buffer data contains a NUL byte?
Then using strncpy here would copy too little, mistakenly
stopping at that NUL byte.

  strncpy (buffer, (char const *) buf_begin + idx, match_len);
  buffer[match_len] = '\0';

That would be a significant bug, definitely worth fixing...

However, so far I have been unable to exercise that code and suspect
that it is all dead code (starting with the above statements).

The test added below makes execution reach the following loop,
which no other test case did.

This code is immediately preceding the strncpy stmt listed above.

  /* match with a character class?  */
  for (i = 0; i < work_mbc->nch_classes; i++)
    {
      if (iswctype ((wint_t) wc, work_mbc->ch_classes[i]))
        goto charset_matched;
    }

If anyone can find a way to get past this loop, please
tell us so we can add a test case to do that.


>From 13191ac43e8bac47c18557753675abf3a4668cb4 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 14 Apr 2012 11:08:23 +0200
Subject: [PATCH 4/4] tests: add a case to exercise one more block in
 match_mb_charset

* tests/empty: Add add a test case for slightly improved coverage.
---
 tests/empty |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tests/empty b/tests/empty
index c13b094..cdd3130 100755
--- a/tests/empty
+++ b/tests/empty
@@ -75,6 +75,13 @@ for locale in C en_US.UTF-8; do
                 echo "Status: Wrong status code, test \#8 failed ($options 
$locale)"
                 failures=1
         fi
+
+        # As above, but exercise a slightly different path with multi-byte 
input.
+        echo "İ" | LC_ALL=$locale timeout 10s grep $options -f /dev/null -e ""
+        if test $? -ne 1 ; then
+                echo "Status: Wrong status code, test \#9 failed ($options 
$locale)"
+                failures=1
+        fi
     done
 done

--
1.7.10.130.g36e6c



reply via email to

[Prev in Thread] Current Thread [Next in Thread]