From 9ab8c46ce334bb62a1581a5ca8b9d3a68dd3aa7c Mon Sep 17 00:00:00 2001 From: Ismail Pazarbasi Date: Fri, 18 Sep 2015 21:54:47 +0000 Subject: [PATCH] Analyzer: Fix a crasher in UbigraphViz Summary: Name `Out` refers to the parameter. It is moved into the member `Out` in ctor-init. Dereferencing null pointer will crash clang, if user passes '-analyzer-viz-egraph-ubigraph' argument. Reviewers: zaks.anna, krememek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D12119 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248050 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp | 5 +++-- test/Analysis/ubigraph-viz.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 test/Analysis/ubigraph-viz.cpp diff --git a/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp index 7a9826be74..ca92ffe8f0 100644 --- a/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp +++ b/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp @@ -778,8 +778,9 @@ void UbigraphViz::AddEdge(ExplodedNode *Src, ExplodedNode *Dst) { << ", ('arrow','true'), ('oriented', 'true'))\n"; } -UbigraphViz::UbigraphViz(std::unique_ptr Out, StringRef Filename) - : Out(std::move(Out)), Filename(Filename), Cntr(0) { +UbigraphViz::UbigraphViz(std::unique_ptr OutStream, + StringRef Filename) + : Out(std::move(OutStream)), Filename(Filename), Cntr(0) { *Out << "('vertex_style_attribute', 0, ('shape', 'icosahedron'))\n"; *Out << "('vertex_style', 1, 0, ('shape', 'sphere'), ('color', '#ffcc66')," diff --git a/test/Analysis/ubigraph-viz.cpp b/test/Analysis/ubigraph-viz.cpp new file mode 100644 index 0000000000..0cb9bd6d89 --- /dev/null +++ b/test/Analysis/ubigraph-viz.cpp @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.API -analyzer-viz-egraph-ubigraph -verify %s +// expected-no-diagnostics + +int f(int x) { + return x < 0 ? 0 : 42; +} + -- 2.50.1