cmJSONState: Avoid UB on empty error message

The caller for `GetErrorMessage` _should_ only be calling this method
if there actual errors (i.e., `!errors.empty()`). However, in the
incidental absence of the intended usage, avoid `pop_back` on an empty
string.
This commit is contained in:
Tyler Yankee
2026-08-20 08:37:00 -04:00
parent 419e5f0d6b
commit 3796649167
+3 -1
View File
@@ -78,7 +78,9 @@ std::string cmJSONState::GetErrorMessage(bool showContext)
message = cmStrCat(message, GetJsonContext(loc), '\n');
}
}
message.pop_back();
if (!message.empty()) {
message.pop_back();
}
return message;
}