[PATCH] D53509: Fix llvm-strings crash for negative char values

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 23 02:54:42 PDT 2018


jhenderson updated this revision to Diff 170596.
jhenderson retitled this revision from "Add unsgined char StringRef constructor/Fix llvm-strings crash" to "Fix llvm-strings crash for negative char values".
jhenderson edited the summary of this revision.
jhenderson added subscribers: andrewng, edd, bd1976llvm, gbreynoo, chrisjackson.
jhenderson added a comment.

Remove unsigned char `StringRef` constructor, use `llvm::isPrint`, and improve test to show that the negative character is not printed.


Repository:
  rL LLVM

https://reviews.llvm.org/D53509

Files:
  test/tools/llvm-strings/negative-char.test
  tools/llvm-strings/llvm-strings.cpp


Index: tools/llvm-strings/llvm-strings.cpp
===================================================================
--- tools/llvm-strings/llvm-strings.cpp
+++ tools/llvm-strings/llvm-strings.cpp
@@ -80,7 +80,7 @@
   const char *B = Contents.begin();
   const char *P = nullptr, *E = nullptr, *S = nullptr;
   for (P = Contents.begin(), E = Contents.end(); P < E; ++P) {
-    if (std::isgraph(*P) || std::isblank(*P)) {
+    if (isPrint(*P) || *P == '\t') {
       if (S == nullptr)
         S = P;
     } else if (S) {
Index: test/tools/llvm-strings/negative-char.test
===================================================================
--- test/tools/llvm-strings/negative-char.test
+++ test/tools/llvm-strings/negative-char.test
@@ -0,0 +1,3 @@
+# RUN: echo -e z\0\x80\0a\0 | llvm-strings --bytes 1 - | FileCheck %s
+# CHECK: z{{$}}
+# CHECK-NEXT: {{^}} a


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53509.170596.patch
Type: text/x-patch
Size: 854 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181023/8ac36007/attachment.bin>


More information about the llvm-commits mailing list