aboutsummaryrefslogtreecommitdiff
path: root/clang/tools/c-index-test/c-index-test.c
diff options
context:
space:
mode:
authorXing Xue <xingxue@outlook.com>2019-06-26 19:27:16 +0000
committerXing Xue <xingxue@outlook.com>2019-06-26 19:27:16 +0000
commit600941e34fed7fbbc68b3380ea1f63b28809035f (patch)
treea08f17e82e1a0e9334f44ef8f59ad1f1e9f26d10 /clang/tools/c-index-test/c-index-test.c
parent730a95c88aff8ceb7bd88cd4d8f30f533896cfb2 (diff)
downloadllvm-600941e34fed7fbbc68b3380ea1f63b28809035f.zip
llvm-600941e34fed7fbbc68b3380ea1f63b28809035f.tar.gz
llvm-600941e34fed7fbbc68b3380ea1f63b28809035f.tar.bz2
Print NULL as "(null)" in diagnostic message
Summary: Passing a null pointer to the printf family for a %s format specifier leads to undefined behaviour. The tests currently expect (null). Explicitly test for a null pointer and provide the expected string. Authored By: andusy Reviewers: hubert.reinterpretcast, xingxue, jasonliu, daltenty, cebowleratibm Reviewed By: hubert.reinterpretcast Subscribers: arphaman, jsji, cfe-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63786 llvm-svn: 364462
Diffstat (limited to 'clang/tools/c-index-test/c-index-test.c')
-rw-r--r--clang/tools/c-index-test/c-index-test.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index 4032631..3375171 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -1053,7 +1053,8 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) {
if (Cursor.kind == CXCursor_InclusionDirective) {
CXFile File = clang_getIncludedFile(Cursor);
CXString Included = clang_getFileName(File);
- printf(" (%s)", clang_getCString(Included));
+ const char *IncludedString = clang_getCString(Included);
+ printf(" (%s)", IncludedString ? IncludedString : "(null)");
clang_disposeString(Included);
if (clang_isFileMultipleIncludeGuarded(TU, File))
@@ -4644,18 +4645,19 @@ static void printDiagnosticSet(CXDiagnosticSet Diags, unsigned indent) {
CXFile File;
CXString FileName, DiagSpelling, DiagOption, DiagCat;
unsigned line, column, offset;
- const char *DiagOptionStr = 0, *DiagCatStr = 0;
+ const char *FileNameStr = 0, *DiagOptionStr = 0, *DiagCatStr = 0;
D = clang_getDiagnosticInSet(Diags, i);
DiagLoc = clang_getDiagnosticLocation(D);
clang_getExpansionLocation(DiagLoc, &File, &line, &column, &offset);
FileName = clang_getFileName(File);
+ FileNameStr = clang_getCString(FileName);
DiagSpelling = clang_getDiagnosticSpelling(D);
-
+
printIndent(indent);
fprintf(stderr, "%s:%d:%d: %s: %s",
- clang_getCString(FileName),
+ FileNameStr ? FileNameStr : "(null)",
line,
column,
getSeverityString(clang_getDiagnosticSeverity(D)),