I came across this bug in dynarr.c: The size of the memory region that
needs to be copied is not correctly calculated.
I'll commit tomorrow, if nobody objects.
src/ChangeLog addition:
2006-01-19 Marcus Crestani <crestani(a)xemacs.org>
* dynarr.c (Dynarr_realloc): Determine size of memory region to
copy correctly, fix types.
* dynarr.c (Dynarr_lisp_realloc): Determine size of memory region
to copy correctly.
* dynarr.c (Dynarr_resize): Call Dynarr_realloc with number of
elements instead of memory region size.
xemacs-21.5 source patch:
Diff command: cvs -q diff -u
Files affected: src/dynarr.c
Index: src/dynarr.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/dynarr.c,v
retrieving revision 1.13
diff -u -r1.13 dynarr.c
--- src/dynarr.c 25 Nov 2005 01:41:59 -0000 1.13
+++ src/dynarr.c 19 Jan 2006 14:14:04 -0000
@@ -129,16 +129,17 @@
static int Dynarr_min_size = 8;
static void
-Dynarr_realloc (Dynarr *dy, Bytecount new_size)
+Dynarr_realloc (Dynarr *dy, int new_size)
{
if (DUMPEDP (dy->base))
{
void *new_base = malloc (new_size);
- memcpy (new_base, dy->base, dy->max > new_size ? dy->max : new_size);
+ memcpy (new_base, dy->base,
+ (dy->max < new_size ? dy->max : new_size) * dy->elsize);
dy->base = new_base;
}
else
- dy->base = xrealloc (dy->base, new_size);
+ dy->base = xrealloc (dy->base, new_size * dy->elsize);
}
void *
@@ -158,13 +159,13 @@
Dynarr);
static void
-Dynarr_lisp_realloc (Dynarr *dy, Elemcount new_size)
+Dynarr_lisp_realloc (Dynarr *dy, int new_size)
{
void *new_base = alloc_lrecord_array (dy->elsize, new_size, dy->lisp_imp);
void *old_base = dy->base;
if (dy->base)
memcpy (new_base, dy->base,
- (dy->max > new_size ? dy->max : new_size) * dy->elsize);
+ (dy->max < new_size ? dy->max : new_size) * dy->elsize);
dy->base = new_base;
if (old_base)
mc_free (old_base);
@@ -205,9 +206,9 @@
if (dy->lisp_imp)
Dynarr_lisp_realloc (dy, newsize);
else
- Dynarr_realloc (dy, newsize*dy->elsize);
+ Dynarr_realloc (dy, newsize);
#else /* not NEW_GC */
- Dynarr_realloc (dy, newsize*dy->elsize);
+ Dynarr_realloc (dy, newsize);
#endif /* not NEW_GC */
dy->max = newsize;
}
--
Marcus