diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-03-16 22:30:13 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-03-16 22:30:13 +0000 |
commit | dc970f086663cf5ade0ccac79f8cb58e4bf110d5 (patch) | |
tree | c68a90dbc91ba7b70e8c81204e5293e6554a8178 /clang/lib/Lex/PPDirectives.cpp | |
parent | a41f71212a677f56c908c178ca679e17875c0052 (diff) | |
download | bcm5719-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/PPDirectives.cpp')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 3bf3fc4af91..7b601010b20 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -71,7 +71,11 @@ void Preprocessor::ReadMacroName(Token &MacroNameTok, char isDefineUndef) { IdentifierInfo *II = MacroNameTok.getIdentifierInfo(); if (II == 0) { - std::string Spelling = getSpelling(MacroNameTok); + bool Invalid = false; + std::string Spelling = getSpelling(MacroNameTok, &Invalid); + if (Invalid) + return; + const IdentifierInfo &Info = Identifiers.get(Spelling); if (Info.isCPlusPlusOperatorKeyword()) // C++ 2.5p2: Alternative tokens behave the same as its primary token @@ -619,8 +623,11 @@ static bool GetLineValue(Token &DigitTok, unsigned &Val, llvm::SmallString<64> IntegerBuffer; IntegerBuffer.resize(DigitTok.getLength()); const char *DigitTokBegin = &IntegerBuffer[0]; - unsigned ActualLength = PP.getSpelling(DigitTok, DigitTokBegin); - + bool Invalid = false; + unsigned ActualLength = PP.getSpelling(DigitTok, DigitTokBegin, &Invalid); + if (Invalid) + return true; + // Verify that we have a simple digit-sequence, and compute the value. This // is always a simple digit string computed in decimal, so we do this manually // here. @@ -905,8 +912,12 @@ void Preprocessor::HandleIdentSCCSDirective(Token &Tok) { // Verify that there is nothing after the string, other than EOM. CheckEndOfDirective("ident"); - if (Callbacks) - Callbacks->Ident(Tok.getLocation(), getSpelling(StrTok)); + if (Callbacks) { + bool Invalid = false; + std::string Str = getSpelling(StrTok, &Invalid); + if (!Invalid) + Callbacks->Ident(Tok.getLocation(), Str); + } } //===----------------------------------------------------------------------===// |