[PATCH] D42057: [FileCheck] - Do not crash on empty document when parsing --check-prefix.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 15 03:05:06 PST 2018


grimar created this revision.
grimar added reviewers: arsenm, rafael.
Herald added a subscriber: wdng.

FileCheck tool crashes when trying to parce check prefix if there is no any lines after.

For example following test would crash if there is no symbols (no EOL mark) after `boom`:

  # REQUIRES: x86
  # RUN: <skipped few lines>
  # RUN: llvm-readobj -t %t | FileCheck %s --check-prefix=boom

Patch fixes the issue.


https://reviews.llvm.org/D42057

Files:
  test/FileCheck/check-empty2.txt
  utils/FileCheck/FileCheck.cpp


Index: utils/FileCheck/FileCheck.cpp
===================================================================
--- utils/FileCheck/FileCheck.cpp
+++ utils/FileCheck/FileCheck.cpp
@@ -718,6 +718,9 @@
 }
 
 static Check::CheckType FindCheckType(StringRef Buffer, StringRef Prefix) {
+  if (Buffer.size() <= Prefix.size())
+    return Check::CheckNone;
+
   char NextChar = Buffer[Prefix.size()];
 
   // Verify that the : is present after the prefix.
Index: test/FileCheck/check-empty2.txt
===================================================================
--- test/FileCheck/check-empty2.txt
+++ test/FileCheck/check-empty2.txt
@@ -0,0 +1,3 @@
+; Check that tool does not crash for empty file.
+
+; RUN: not FileCheck -input-file %s %s -check-prefix=A
\ No newline at end of file


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42057.129823.patch
Type: text/x-patch
Size: 774 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180115/836672a7/attachment.bin>


More information about the llvm-commits mailing list