]> granicus.if.org Git - clang/commitdiff
Analyzer: Fix a crasher in UbigraphViz
authorIsmail Pazarbasi <ismail.pazarbasi@gmail.com>
Fri, 18 Sep 2015 21:54:47 +0000 (21:54 +0000)
committerIsmail Pazarbasi <ismail.pazarbasi@gmail.com>
Fri, 18 Sep 2015 21:54:47 +0000 (21:54 +0000)
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
test/Analysis/ubigraph-viz.cpp [new file with mode: 0644]

index 7a9826be746b95dcf7d99c3b1fbd2f12a289e992..ca92ffe8f01d6c4ee7e9d057b7513c15b7840393 100644 (file)
@@ -778,8 +778,9 @@ void UbigraphViz::AddEdge(ExplodedNode *Src, ExplodedNode *Dst) {
        << ", ('arrow','true'), ('oriented', 'true'))\n";
 }
 
-UbigraphViz::UbigraphViz(std::unique_ptr<raw_ostream> Out, StringRef Filename)
-    : Out(std::move(Out)), Filename(Filename), Cntr(0) {
+UbigraphViz::UbigraphViz(std::unique_ptr<raw_ostream> 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 (file)
index 0000000..0cb9bd6
--- /dev/null
@@ -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;
+}
+