]> mj.ucw.cz Git - libucw.git/commitdiff
HEAP_DELETE: Copy the `pos' parameter to a temporary variable as soon
authorMartin Mares <mj@ucw.cz>
Fri, 2 Nov 2001 21:34:08 +0000 (21:34 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 2 Nov 2001 21:34:08 +0000 (21:34 +0000)
soon as possible to avoid problems with callers supplying us with expressions
which could change during heap operations.

lib/heap.h

index 268cc2572cd8d3ad855464d7c8a6e2a5b41dead7..7be54cfa54665ee1808c00c0fb8ce9e2b78a661a 100644 (file)
@@ -71,9 +71,9 @@
   do {                                                                                 \
     uns j, l, u;                                                                       \
     type x;                                                                            \
-    swap(heap,pos,num,x);                                                              \
-    num--;                                                                             \
     j = pos;                                                                           \
+    swap(heap,j,num,x);                                                                        \
+    num--;                                                                             \
     if (less(heap[j], heap[num+1]))                                                    \
       HEAP_BUBBLE_UP_J(heap,num,less,swap)                                             \
     else                                                                               \