[dia] [scan-build] Result of operation is garbage or undefined



commit e9299047ad63a9da62dfb289f63ebc58cc4f0eb4
Author: Hans Breuer <hans breuer org>
Date:   Sun Jun 8 15:17:43 2014 +0200

    [scan-build] Result of operation is garbage or undefined
    
    Silence scan-build by using the return value of GetNodePosition()
    although not initializing would never happen with SrcNode and
    dstNode being valid (checked before).
    The real bug was not using dstNode at all for the second query.

 plug-ins/layout/ogdf-simple.cpp |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/plug-ins/layout/ogdf-simple.cpp b/plug-ins/layout/ogdf-simple.cpp
index 0d52dbe..7080b02 100644
--- a/plug-ins/layout/ogdf-simple.cpp
+++ b/plug-ins/layout/ogdf-simple.cpp
@@ -153,9 +153,11 @@ KGraph::AddEdge (int srcNode, int dstNode, double* coords, int len)
     src = m_nodes[srcNode];
     dst = m_nodes[dstNode];
     double xs, xd, ys, yd;
-    GetNodePosition (srcNode, &xs, &ys);
-    GetNodePosition (srcNode, &xd, &yd);
-    double dist = sqrt((xd - xs) * (xd - xs) + (yd - ys) * (yd - ys)) * m_scale;
+    double dist;
+    if (GetNodePosition (srcNode, &xs, &ys) && GetNodePosition (dstNode, &xd, &yd))
+       dist = sqrt((xd - xs) * (xd - xs) + (yd - ys) * (yd - ys)) * m_scale;
+    else
+       dist = 0.0;
 
     edge = m_pGraph->newEdge(src, dst);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]