[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Updated fix of array_rshift() in array.c
From: |
William Park |
Subject: |
Updated fix of array_rshift() in array.c |
Date: |
Tue, 31 May 2005 16:35:15 -0400 |
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/local/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -O4
uname output: Linux node1 2.6.11-smp #2 SMP Thu Mar 3 09:53:04 EST 2005 i686
unknown unknown GNU/Linux
Machine Type: i686-pc-linux-gnu
Bash Version: 3.0
Patch Level: 0
Release Status: release
Description:
It's not visible to user. But, I remember submitting a fix for
this problem. Here is an updated patch.
In array_rshift() in array.c, 'max_index' is incremented, even
if array is empty. So, if shift is greater than 1 (say, 5),
then 'max_index' will end up being fictitious. You won't be
able to insert any item from 1 to 5. You have to insert at
index greater than 5 in order to force 'max_index' to be real
again. Then, you can insert as normal.
Fix:
--- ../bash-3.0/array.c 2004-05-06 08:24:13.000000000 -0400
+++ array.c 2005-05-31 16:21:24.000000000 -0400
@@ -255,7 +255,9 @@
a->num_elements++;
}
+#if 0 /* Move to the end. --William */
a->max_index += n;
+#endif
/*
* Renumber all elements in the array except the one we just added.
@@ -263,6 +265,14 @@
for ( ; ae != a->head; ae = element_forw(ae))
element_index(ae) += n;
+ /* Fix: If array is empty and you shift 5, then 'max_index' increases
+ * from -1 to 4. But, you still have empty array (if S is NULL) or have
+ * only element (ie. array[0]=S). Later on, array_insert() cannot find
+ * place to insert for array[1] to array[4]. Adjust 'max_index' after
+ * all other indexes have been incremented. --William
+ */
+ a->max_index = element_index (a->head->prev);
+
return (a->num_elements);
}
@@ -451,7 +461,10 @@
*/
array_dispose_element(new);
free(element_value(ae));
- ae->value = savestring(v);
+
+ /* Fix: savestring() cannot take NULL argument
--William */
+ ae->value = v ? savestring(v) : (char *)NULL;
+
return(0);
} else if (element_index(ae) > i) {
ADD_BEFORE(ae, new);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Updated fix of array_rshift() in array.c,
William Park <=