diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2016-11-12 03:39:21 +0000 |
---|---|---|
committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2016-11-12 03:39:21 +0000 |
commit | 2729786ffff8e74acbc179155364a30897d1affd (patch) | |
tree | 72bb9436c49f307afe8f568cdd8fbde51e299a10 | |
parent | 4dcf92a27ec70670f23ced082e3bbcf28f1dbc71 (diff) | |
download | bcm5719-llvm-2729786ffff8e74acbc179155364a30897d1affd.tar.gz bcm5719-llvm-2729786ffff8e74acbc179155364a30897d1affd.zip |
llvm-strings: ensure that the last string is correctly printed
We would ignore the last string that appeared if the file ended with a printable
character. Ensure that we get the last string.
llvm-svn: 286706
-rw-r--r-- | llvm/test/tools/llvm-strings/terminator-neg.test | 2 | ||||
-rw-r--r-- | llvm/test/tools/llvm-strings/terminator.test | 2 | ||||
-rw-r--r-- | llvm/tools/llvm-strings/llvm-strings.cpp | 6 |
3 files changed, 8 insertions, 2 deletions
diff --git a/llvm/test/tools/llvm-strings/terminator-neg.test b/llvm/test/tools/llvm-strings/terminator-neg.test new file mode 100644 index 00000000000..cdcf52498f6 --- /dev/null +++ b/llvm/test/tools/llvm-strings/terminator-neg.test @@ -0,0 +1,2 @@ +RUN: echo -n abc | llvm-strings - | FileCheck -allow-empty %s +CHECK-NOT: abc diff --git a/llvm/test/tools/llvm-strings/terminator.test b/llvm/test/tools/llvm-strings/terminator.test new file mode 100644 index 00000000000..d27eeebe2e7 --- /dev/null +++ b/llvm/test/tools/llvm-strings/terminator.test @@ -0,0 +1,2 @@ +RUN: echo -n abcdefg | llvm-strings - | FileCheck %s +CHECK: abcdefg diff --git a/llvm/tools/llvm-strings/llvm-strings.cpp b/llvm/tools/llvm-strings/llvm-strings.cpp index d590b7012b6..dbabf08a52f 100644 --- a/llvm/tools/llvm-strings/llvm-strings.cpp +++ b/llvm/tools/llvm-strings/llvm-strings.cpp @@ -33,8 +33,8 @@ static cl::list<std::string> InputFileNames(cl::Positional, cl::ZeroOrMore); static void dump(raw_ostream &OS, StringRef Contents) { - const char *S = nullptr; - for (const char *P = Contents.begin(), *E = Contents.end(); P < E; ++P) { + 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 (S == nullptr) S = P; @@ -44,6 +44,8 @@ static void dump(raw_ostream &OS, StringRef Contents) { S = nullptr; } } + if (S && E - S > 3) + OS << StringRef(S, E - S) << '\n'; } namespace { |