summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/MacroArgs.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-03-16 22:30:13 +0000
committerDouglas Gregor <dgregor@apple.com>2010-03-16 22:30:13 +0000
commitdc970f086663cf5ade0ccac79f8cb58e4bf110d5 (patch)
treec68a90dbc91ba7b70e8c81204e5293e6554a8178 /clang/lib/Lex/MacroArgs.cpp
parenta41f71212a677f56c908c178ca679e17875c0052 (diff)
downloadbcm5719-llvm-dc970f086663cf5ade0ccac79f8cb58e4bf110d5.tar.gz
bcm5719-llvm-dc970f086663cf5ade0ccac79f8cb58e4bf110d5.zip
Audit all Preprocessor::getSpelling() callers, improving failure
recovery for those that need it. llvm-svn: 98689
Diffstat (limited to 'clang/lib/Lex/MacroArgs.cpp')
-rw-r--r--clang/lib/Lex/MacroArgs.cpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/clang/lib/Lex/MacroArgs.cpp b/clang/lib/Lex/MacroArgs.cpp
index 2f1a34c8329..89f6368a277 100644
--- a/clang/lib/Lex/MacroArgs.cpp
+++ b/clang/lib/Lex/MacroArgs.cpp
@@ -208,24 +208,31 @@ Token MacroArgs::StringifyArgument(const Token *ArgToks,
if (Tok.is(tok::string_literal) || // "foo"
Tok.is(tok::wide_string_literal) || // L"foo"
Tok.is(tok::char_constant)) { // 'x' and L'x'.
- std::string Str = Lexer::Stringify(PP.getSpelling(Tok));
- Result.append(Str.begin(), Str.end());
+ bool Invalid = false;
+ std::string TokStr = PP.getSpelling(Tok, &Invalid);
+ if (!Invalid) {
+ std::string Str = Lexer::Stringify(TokStr);
+ Result.append(Str.begin(), Str.end());
+ }
} else {
// Otherwise, just append the token. Do some gymnastics to get the token
// in place and avoid copies where possible.
unsigned CurStrLen = Result.size();
Result.resize(CurStrLen+Tok.getLength());
const char *BufPtr = &Result[CurStrLen];
- unsigned ActualTokLen = PP.getSpelling(Tok, BufPtr);
-
- // If getSpelling returned a pointer to an already uniqued version of the
- // string instead of filling in BufPtr, memcpy it onto our string.
- if (BufPtr != &Result[CurStrLen])
- memcpy(&Result[CurStrLen], BufPtr, ActualTokLen);
-
- // If the token was dirty, the spelling may be shorter than the token.
- if (ActualTokLen != Tok.getLength())
- Result.resize(CurStrLen+ActualTokLen);
+ bool Invalid = false;
+ unsigned ActualTokLen = PP.getSpelling(Tok, BufPtr, &Invalid);
+
+ if (!Invalid) {
+ // If getSpelling returned a pointer to an already uniqued version of
+ // the string instead of filling in BufPtr, memcpy it onto our string.
+ if (BufPtr != &Result[CurStrLen])
+ memcpy(&Result[CurStrLen], BufPtr, ActualTokLen);
+
+ // If the token was dirty, the spelling may be shorter than the token.
+ if (ActualTokLen != Tok.getLength())
+ Result.resize(CurStrLen+ActualTokLen);
+ }
}
}
OpenPOWER on IntegriCloud