From 5b2e968264b4bd80e4ba0650cdd7e0e56b0f8cdd Mon Sep 17 00:00:00 2001 From: James Henderson Date: Wed, 24 Oct 2018 13:16:16 +0000 Subject: Fix llvm-strings crash for negative char values On Windows at least, llvm-strings was crashing if it encountered bytes that mapped to negative chars, as it was passing these into std::isgraph and std::isblank functions, resulting in undefined behaviour. On debug builds using MSVC, these functions verfiy that the value passed in is representable as an unsigned char. Since the char is promoted to an int, a value greater than 127 would turn into a negative integer value, and fail the check. Using the llvm::isPrint function is sufficient to solve the issue. Reviewed by: ruiu, mstorsjo Differential Revision: https://reviews.llvm.org/D53509 llvm-svn: 345137 --- llvm/tools/llvm-strings/llvm-strings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'llvm/tools/llvm-strings/llvm-strings.cpp') diff --git a/llvm/tools/llvm-strings/llvm-strings.cpp b/llvm/tools/llvm-strings/llvm-strings.cpp index 8e2d213..c355caf 100644 --- a/llvm/tools/llvm-strings/llvm-strings.cpp +++ b/llvm/tools/llvm-strings/llvm-strings.cpp @@ -80,7 +80,7 @@ static void strings(raw_ostream &OS, StringRef FileName, StringRef Contents) { 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) { -- cgit v1.1