comparison src/redraw_man.c @ 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 257a1d314bcd
children 4c2d83721bcc
comparison
equal deleted inserted replaced
120:5df7403b6fbc 121:76ba6fd61c7d
38 * at offset specified by 'off' from start address of elemnts. 38 * at offset specified by 'off' from start address of elemnts.
39 */ 39 */
40 static void _insert_sort(void **elms, int num, int off) { 40 static void _insert_sort(void **elms, int num, int off) {
41 int i, j; 41 int i, j;
42 unsigned int val; 42 unsigned int val;
43 void *elm_i;
43 44
44 for(i = 1; i < num; i++) { 45 for(i = 1; i < num; i++) {
45 val = *(unsigned int *)(elms[i] + off); 46 elm_i = elms[i];
47 val = *(unsigned int *)(elm_i + off);
46 for(j = i; j > 0; j--) { 48 for(j = i; j > 0; j--) {
47 if(*(unsigned int *)(elms[j - 1] + off) <= val) 49 if(*(unsigned int *)(elms[j - 1] + off) <= val)
48 break; 50 break;
49 elms[j] = elms[j - 1]; 51 elms[j] = elms[j - 1];
50 } 52 }
51 elms[j] = elms[i]; 53 elms[j] = elm_i;
52 } 54 }
53 } 55 }
54 56
55 static int extend_memblk(void **buf, int o_size, int n_size) { 57 static int extend_memblk(void **buf, int o_size, int n_size) {
56 void *new_buf; 58 void *new_buf;