[llvm] 2225797 - [YAMLParser] Scanner::setError - ensure we use the StringRef::iterator argument (PR45043)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 3 10:55:51 PDT 2020
Author: Simon Pilgrim
Date: 2020-04-03T18:55:38+01:00
New Revision: 22257975679d20dd87cb3f791708d07c82f53142
URL: https://github.com/llvm/llvm-project/commit/22257975679d20dd87cb3f791708d07c82f53142
DIFF: https://github.com/llvm/llvm-project/commit/22257975679d20dd87cb3f791708d07c82f53142.diff
LOG: [YAMLParser] Scanner::setError - ensure we use the StringRef::iterator argument (PR45043)
As detailed on PR45043, static analysis was warning that the StringRef::iterator Position argument was being ignored and the function was hardwired to use the Current iterator.
This patch ensures we use the provided iterator and removes the (barely necessary) setError wrapper that always used Current.
Differential Revision: https://reviews.llvm.org/D76512
Added:
Modified:
llvm/lib/Support/YAMLParser.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp
index 4f9feee4a8a0..ca8ffdc47afa 100644
--- a/llvm/lib/Support/YAMLParser.cpp
+++ b/llvm/lib/Support/YAMLParser.cpp
@@ -268,8 +268,8 @@ class Scanner {
}
void setError(const Twine &Message, StringRef::iterator Position) {
- if (Current >= End)
- Current = End - 1;
+ if (Position >= End)
+ Position = End - 1;
// propagate the error if possible
if (EC)
@@ -278,14 +278,10 @@ class Scanner {
// Don't print out more errors after the first one we encounter. The rest
// are just the result of the first, and have no meaning.
if (!Failed)
- printError(SMLoc::getFromPointer(Current), SourceMgr::DK_Error, Message);
+ printError(SMLoc::getFromPointer(Position), SourceMgr::DK_Error, Message);
Failed = true;
}
- void setError(const Twine &Message) {
- setError(Message, Current);
- }
-
/// Returns true if an error occurred while parsing.
bool failed() {
return Failed;
@@ -934,13 +930,13 @@ void Scanner::scan_ns_uri_char() {
bool Scanner::consume(uint32_t Expected) {
if (Expected >= 0x80) {
- setError("Cannot consume non-ascii characters");
+ setError("Cannot consume non-ascii characters", Current);
return false;
}
if (Current == End)
return false;
if (uint8_t(*Current) >= 0x80) {
- setError("Cannot consume non-ascii characters");
+ setError("Cannot consume non-ascii characters", Current);
return false;
}
if (uint8_t(*Current) == Expected) {
@@ -1763,7 +1759,7 @@ bool Scanner::fetchMoreTokens() {
&& !isBlankOrBreak(Current + 2)))
return scanPlainScalar();
- setError("Unrecognized character while tokenizing.");
+ setError("Unrecognized character while tokenizing.", Current);
return false;
}
More information about the llvm-commits
mailing list