]> granicus.if.org Git - graphviz/commitdiff
cgraph: fix incorrect resize-down implementation for lists without destructors
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 10 Dec 2022 20:33:16 +0000 (12:33 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 11 Dec 2022 18:37:29 +0000 (10:37 -0800)
Attempting to shrink a list that did not have a element destructor would
incorrectly do nothing.

lib/cgraph/list.h

index e7f4c2351dff30bb4026f5195def32dfb2d0dae6..044b1dd24c6c504d49a04f0df636ae1b9a214fa2 100644 (file)
       }                                                                        \
     } else if (list->size > size) {                                            \
       /* we are shrinking the list */                                          \
-      if (list->dtor != NULL) {                                                \
-        while (list->size > size) {                                            \
+      while (list->size > size) {                                              \
+        if (list->dtor != NULL) {                                              \
           list->dtor(list->data[list->size - 1]);                              \
-          --list->size;                                                        \
         }                                                                      \
+        --list->size;                                                          \
       }                                                                        \
     }                                                                          \
   }                                                                            \