Skip to content

Commit 9a1f4db

Browse files
committed
[FileCheck] Fix parsing empty global and pseudo variable names
In `Pattern::parseVariable`, for global variables (those starting with '$') and for pseudo variables (those starting with '@') the first character is consumed before actual variable name parsing. If the name is empty, it leads to out-of-bound access to the corresponding `StringRef`. This patch adds an if statement against the case described.
1 parent 6f0e39c commit 9a1f4db

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

llvm/lib/FileCheck/FileCheck.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ Pattern::parseVariable(StringRef &Str, const SourceMgr &SM) {
297297
if (Str[0] == '$' || IsPseudo)
298298
++I;
299299

300+
if (I == Str.size())
301+
return ErrorDiagnostic::get(SM, Str,
302+
StringRef("empty ") +
303+
(IsPseudo ? "pseudo " : "global ") +
304+
"variable name");
305+
300306
if (!isValidVarNameStart(Str[I++]))
301307
return ErrorDiagnostic::get(SM, Str, "invalid variable name");
302308

0 commit comments

Comments
 (0)