diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-05-17 22:09:53 +0000 | 
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-05-17 22:09:53 +0000 | 
| commit | f15eac1110cc963cabda42759e6eb9d6f077f30a (patch) | |
| tree | 6e98d79bd5787da74fae1bf67d1e9c15f91e8143 /clang | |
| parent | af9b325d232f52ca858c67cd497b79f5e63716af (diff) | |
| download | bcm5719-llvm-f15eac1110cc963cabda42759e6eb9d6f077f30a.tar.gz bcm5719-llvm-f15eac1110cc963cabda42759e6eb9d6f077f30a.zip  | |
Do some safety checks.
llvm-svn: 131491
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 6 | ||||
| -rw-r--r-- | clang/tools/libclang/CIndex.cpp | 16 | 
2 files changed, 11 insertions, 11 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index c3e03933e5e..ae7de2d3c95 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -961,6 +961,12 @@ static void ComputeLineNumbers(Diagnostic &Diag, ContentCache *FI,  /// about to emit a diagnostic.  unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos,                                         bool *Invalid) const { +  if (FID.isInvalid()) { +    if (Invalid) +      *Invalid = true; +    return 1; +  } +    ContentCache *Content;    if (LastLineNoFileIDQuery == FID)      Content = LastLineNoContentCache; diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index f1a37d6906b..00141184c70 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -2819,17 +2819,8 @@ void clang_getSpellingLocation(CXSourceLocation location,                                 unsigned *offset) {    SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data); -  if (!location.ptr_data[0] || Loc.isInvalid()) { -    if (file) -      *file = 0; -    if (line) -      *line = 0; -    if (column) -      *column = 0; -    if (offset) -      *offset = 0; -    return; -  } +  if (!location.ptr_data[0] || Loc.isInvalid()) +    return createNullLocation(file, line, column, offset);    const SourceManager &SM =      *static_cast<const SourceManager*>(location.ptr_data[0]); @@ -2847,6 +2838,9 @@ void clang_getSpellingLocation(CXSourceLocation location,    FileID FID = LocInfo.first;    unsigned FileOffset = LocInfo.second; +  if (FID.isInvalid()) +    return createNullLocation(file, line, column, offset); +    if (file)      *file = (void *)SM.getFileEntryForID(FID);    if (line)  | 

