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



commit d7ca5945895519630fe3e0378eb5f2beea056faf
Author: Hans Breuer <hans breuer org>
Date:   Sun Jun 8 20:10:57 2014 +0200

    [scan-build] Result of operation is garbage or undefined (not really)
    
    Give scan-build a clue about unchanged num_handles to avoid
    complaints about potentially uninitialized data.
    Also comment about the copy of the code between bus and tree.

 objects/Misc/tree.c   |   10 ++++++----
 objects/network/bus.c |   10 ++++++----
 2 files changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/objects/Misc/tree.c b/objects/Misc/tree.c
index 1576d4b..3fcd258 100644
--- a/objects/Misc/tree.c
+++ b/objects/Misc/tree.c
@@ -206,9 +206,11 @@ tree_move_handle(Tree *tree, Handle *handle,
   real vlen, vlen2;
   real len_scale;
   int i;
+  const int num_handles = tree->num_handles; /* const to help scan-build */
 
-  parallel = (real *)g_alloca (tree->num_handles * sizeof(real));
-  perp = (real *)g_alloca (tree->num_handles * sizeof(real));
+  /* code copied from network/bus.c */
+  parallel = (real *)g_alloca (num_handles * sizeof(real));
+  perp = (real *)g_alloca (num_handles * sizeof(real));
 
   if (handle->id == HANDLE_BUS) {
     handle->pos = *to;
@@ -224,7 +226,7 @@ tree_move_handle(Tree *tree, Handle *handle,
     
     vhatperp.y = -vhat.x;
     vhatperp.x =  vhat.y;
-    for (i=0;i<tree->num_handles;i++) {
+    for (i=0;i<num_handles;i++) {
       u = tree->handles[i]->pos;
       point_sub(&u, &endpoints[0]);
       parallel[i] = point_dot(&vhat, &u);
@@ -244,7 +246,7 @@ tree_move_handle(Tree *tree, Handle *handle,
     point_normalize(&vhat);
     vhatperp.y = -vhat.x;
     vhatperp.x =  vhat.y;
-    for (i=0;i<tree->num_handles;i++) {
+    for (i=0;i<num_handles;i++) {
       if (tree->handles[i]->connected_to == NULL) {
        u = vhat;
        point_scale(&u, parallel[i]*len_scale);
diff --git a/objects/network/bus.c b/objects/network/bus.c
index 3333058..64c5b62 100644
--- a/objects/network/bus.c
+++ b/objects/network/bus.c
@@ -214,9 +214,11 @@ bus_move_handle(Bus *bus, Handle *handle,
   real vlen, vlen2;
   real len_scale;
   int i;
+  const int num_handles = bus->num_handles; /* const to help scan-build */
 
-  parallel = (real *)g_alloca (bus->num_handles * sizeof(real));
-  perp = (real *)g_alloca (bus->num_handles * sizeof(real));
+  /* code copied to Misc/tree.c */
+  parallel = (real *)g_alloca (num_handles * sizeof(real));
+  perp = (real *)g_alloca (num_handles * sizeof(real));
 
   if (handle->id == HANDLE_BUS) {
     handle->pos = *to;
@@ -232,7 +234,7 @@ bus_move_handle(Bus *bus, Handle *handle,
     
     vhatperp.x = -vhat.y;
     vhatperp.y =  vhat.x;
-    for (i=0;i<bus->num_handles;i++) {
+    for (i=0;i<num_handles;i++) {
       u = bus->handles[i]->pos;
       point_sub(&u, &endpoints[0]);
       parallel[i] = point_dot(&vhat, &u);
@@ -252,7 +254,7 @@ bus_move_handle(Bus *bus, Handle *handle,
     point_normalize(&vhat);
     vhatperp.x = -vhat.y;
     vhatperp.y =  vhat.x;
-    for (i=0;i<bus->num_handles;i++) {
+    for (i=0;i<num_handles;i++) {
       if (bus->handles[i]->connected_to == NULL) {
        u = vhat;
        point_scale(&u, parallel[i]*len_scale);


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