diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-03-16 20:46:42 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-03-16 20:46:42 +0000 |
| commit | 42fe858cd6fff76fc8f3e7f6c0c58116782bd246 (patch) | |
| tree | 189b2b29bf6a7b0470a196f0742c2445d4accb9a /clang/lib/Lex | |
| parent | f2e4b5dd7f6e2e80bdfec64205dbf9120eef728f (diff) | |
| download | bcm5719-llvm-42fe858cd6fff76fc8f3e7f6c0c58116782bd246.tar.gz bcm5719-llvm-42fe858cd6fff76fc8f3e7f6c0c58116782bd246.zip | |
Audit all callers of SourceManager::getCharacterData(); update some of
them to recover more gracefully on failure.
llvm-svn: 98672
Diffstat (limited to 'clang/lib/Lex')
| -rw-r--r-- | clang/lib/Lex/Lexer.cpp | 1 | ||||
| -rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 7 | ||||
| -rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 5 |
3 files changed, 10 insertions, 3 deletions
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index 6cdb96f37de..0b8b6242db3 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -163,6 +163,7 @@ Lexer *Lexer::Create_PragmaLexer(SourceLocation SpellingLoc, // Now that the lexer is created, change the start/end locations so that we // just lex the subsection of the file that we want. This is lexing from a // scratch buffer. + bool Invalid = false; const char *StrData = SM.getCharacterData(SpellingLoc); L->BufferPtr = StrData; diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index cddc6cff727..3bf3fc4af91 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -204,7 +204,12 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, // to spell an i/e in a strange way that is another letter. Skipping this // allows us to avoid looking up the identifier info for #define/#undef and // other common directives. - const char *RawCharData = SourceMgr.getCharacterData(Tok.getLocation()); + bool Invalid = false; + const char *RawCharData = SourceMgr.getCharacterData(Tok.getLocation(), + &Invalid); + if (Invalid) + return; + char FirstChar = RawCharData[0]; if (FirstChar >= 'a' && FirstChar <= 'z' && FirstChar != 'i' && FirstChar != 'e') { diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 880ff43c662..a86799aafae 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -428,10 +428,11 @@ SourceLocation Preprocessor::AdvanceToTokenCharacter(SourceLocation TokStart, // Figure out how many physical characters away the specified instantiation // character is. This needs to take into consideration newlines and // trigraphs. - const char *TokPtr = SourceMgr.getCharacterData(TokStart); + bool Invalid = false; + const char *TokPtr = SourceMgr.getCharacterData(TokStart, &Invalid); // If they request the first char of the token, we're trivially done. - if (CharNo == 0 && Lexer::isObviouslySimpleCharacter(*TokPtr)) + if (Invalid || (CharNo == 0 && Lexer::isObviouslySimpleCharacter(*TokPtr))) return TokStart; unsigned PhysOffset = 0; |

