Fixes assertions to not crash StringRef (#534)

We can't read [0] on an empty StringRef or the StringRef itself asserts
(this may crash in non-debug mode as an empty StringRef is not guaranteed to have a valid pointer).
Instead, we can just check if the StringRef is not empty.

Closes #502
This commit is contained in:
Thad House
2017-05-10 20:14:14 -07:00
committed by Peter Johnson
parent 68b62abb52
commit 16e71eac43
2 changed files with 4 additions and 4 deletions

View File

@@ -41,7 +41,7 @@ bool wpi_assert_impl(bool conditionValue, llvm::StringRef conditionText,
errorStream << "Assertion \"" << conditionText << "\" ";
if (message[0] != '\0') {
if (!message.empty()) {
errorStream << "failed: " << message << std::endl;
} else {
errorStream << "failed." << std::endl;
@@ -78,7 +78,7 @@ void wpi_assertEqual_common_impl(llvm::StringRef valueA, llvm::StringRef valueB,
errorStream << "Assertion \"" << valueA << " " << equalityType << " "
<< valueB << "\" ";
if (message[0] != '\0') {
if (!message.empty()) {
errorStream << "failed: " << message << std::endl;
} else {
errorStream << "failed." << std::endl;