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



commit 7959e0d2654294ab189fe2a01046ffd8e8cfeec5
Author: Hans Breuer <hans breuer org>
Date:   Sun Jun 8 17:41:15 2014 +0200

    [scan-build] Result of operation is garbage or undefined (theoretical)
    
    Simlify slightly overengineerd parent_handle_extents() to silence
    scan-build complaining about theoretical undefined values.
    Parents without handles simply must not exist, now also ensured by
    a new unit-test.
    Also removed the return value no caller cared for anyway.

 lib/parent.c         |   31 ++++++++-----------------------
 lib/parent.h         |    2 +-
 tests/test-objects.c |    2 +-
 3 files changed, 10 insertions(+), 25 deletions(-)
---
diff --git a/lib/parent.c b/lib/parent.c
index ba0f248..d6802a2 100644
--- a/lib/parent.c
+++ b/lib/parent.c
@@ -255,35 +255,20 @@ parent_point_extents(Point *point, Rectangle *extents)
  * which is initialized to the biggest rectangle containing
  * all the objects handles
  */
-gboolean
+void
 parent_handle_extents(DiaObject *obj, Rectangle *extents)
 {
   int idx;
-  coord *left_most = NULL, *top_most = NULL, *bottom_most = NULL, *right_most = NULL;
 
-  for (idx = 0; idx < obj->num_handles; idx++)
-  {
+  g_assert (obj->num_handles > 0);
+  /* initialize the rectangle with the first handle */
+  extents->left = extents->right = obj->handles[0]->pos.x;
+  extents->top = extents->bottom = obj->handles[0]->pos.y;
+  /* grow it with the other ones */
+  for (idx = 1; idx < obj->num_handles; idx++) {
     Handle *handle = obj->handles[idx];
-
-    if (!left_most || *left_most > handle->pos.x)
-      left_most = &handle->pos.x;
-    if (!right_most || *right_most < handle->pos.x)
-      right_most = &handle->pos.x;
-    if (!top_most || *top_most > handle->pos.y)
-      top_most = &handle->pos.y;
-    if (!bottom_most || *bottom_most < handle->pos.y)
-      bottom_most = &handle->pos.y;
+    rectangle_add_point (extents, &handle->pos);
   }
-
-  if (!left_most ||  !right_most || !top_most || !bottom_most)
-    return FALSE;
-
-  extents->left = *left_most;
-  extents->right = *right_most;
-  extents->top = *top_most;
-  extents->bottom = *bottom_most;
-
-  return TRUE;
 }
 
 /** Apply a function to all children of the given object (recursively, 
diff --git a/lib/parent.h b/lib/parent.h
index eebe749..80ba6a0 100644
--- a/lib/parent.h
+++ b/lib/parent.h
@@ -24,7 +24,7 @@
 #include "geometry.h"
 
 GList *parent_list_affected(GList *obj_list);
-gboolean parent_handle_extents(DiaObject *obj, Rectangle *extents);
+void parent_handle_extents(DiaObject *obj, Rectangle *extents);
 Point parent_move_child_delta(Rectangle *p_ext, Rectangle *c_text, Point *delta);
 void parent_point_extents(Point *point, Rectangle *extents);
 gboolean parent_list_expand(GList *obj_list);
diff --git a/tests/test-objects.c b/tests/test-objects.c
index c276566..371c9fa 100644
--- a/tests/test-objects.c
+++ b/tests/test-objects.c
@@ -86,6 +86,7 @@ _test_creation (gconstpointer user_data)
   g_assert (o->bounding_box.left <= o->position.x && o->position.x <= o->bounding_box.right);
   g_assert (o->bounding_box.top <= o->position.y && o->position.y <= o->bounding_box.bottom);
 
+  g_assert (o->num_handles > 0);
   /* both handles can be NULL, but if not they must belong to the object  */
   for (i = 0; i < o->num_handles; ++i)
     {
@@ -811,7 +812,6 @@ _ot_item (gpointer key,
   g_test_add_data_func (testpath, type, _test_move_handle);
   g_free (testpath);
 
-  
   testpath = g_strdup_printf ("%s/%s/%s", base, name, "ConnectionPoints");
   g_test_add_data_func (testpath, type, _test_connectionpoint_consistency);
   g_free (testpath);


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