changeset 121:76ba6fd61c7d

More bug of insert sort. elms[i] is over wrote by elms[i-1]. Save it to a local variable at start of loop iteration for elms[i].
author Thinker K.F. Li <thinker@branda.to>
date Sun, 14 Sep 2008 23:40:57 +0800
parents 5df7403b6fbc
children 17e97e92b76e
files src/redraw_man.c
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/redraw_man.c	Sun Sep 14 23:05:30 2008 +0800
+++ b/src/redraw_man.c	Sun Sep 14 23:40:57 2008 +0800
@@ -40,15 +40,17 @@
 static void _insert_sort(void **elms, int num, int off) {
     int i, j;
     unsigned int val;
+    void *elm_i;
 
     for(i = 1; i < num; i++) {
-	val = *(unsigned int *)(elms[i] + off);
+	elm_i = elms[i];
+	val = *(unsigned int *)(elm_i + off);
 	for(j = i; j > 0; j--) {
 	    if(*(unsigned int *)(elms[j - 1] + off) <= val)
 		break;
 	    elms[j] = elms[j - 1];
 	}
-	elms[j] = elms[i];
+	elms[j] = elm_i;
     }
 }