Fix llvm-strings crash for negative char values
authorJames Henderson <jh7370@my.bristol.ac.uk>
Wed, 24 Oct 2018 13:16:16 +0000 (13:16 +0000)
committerJames Henderson <jh7370@my.bristol.ac.uk>
Wed, 24 Oct 2018 13:16:16 +0000 (13:16 +0000)
commit5b2e968264b4bd80e4ba0650cdd7e0e56b0f8cdd
treed821e700fbc7dff35afc1cc7cfed9bab0f84652d
parent84cc11073255b36a08bea594d6e4946b7c782b54
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/test/tools/llvm-strings/negative-char.test [new file with mode: 0644]
llvm/tools/llvm-strings/llvm-strings.cpp