mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
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:
committed by
Peter Johnson
parent
68b62abb52
commit
16e71eac43
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user