# New Ticket Created by "Mehmet Yavuz Selim Soyturk"
# Please include the string: [perl #43105]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=43105 >
Function mmd_expand_y in src/mmd.c allocates new memory for the mmd
table, but does not initialize the newy allocated memory to NULL,
which causes segfaults for some cases. The attached patch solves that
problem.
--
Mehmet
Index: src/mmd.c
===================================================================
--- src/mmd.c (revision 18722)
+++ src/mmd.c (working copy)
@@ -624,18 +624,30 @@
mmd_expand_y(Interp *interp, INTVAL func_nr, INTVAL new_y)
{
funcptr_t *new_table;
- UINTVAL new_size;
+ UINTVAL x;
+ UINTVAL y;
+ UINTVAL i;
+ UINTVAL new_size;
MMD_table * const table = interp->binop_mmd_funcs + func_nr;
assert(table->x);
+
+ x = table->x;
+ y = table->y;
- new_size = sizeof (funcptr_t) * table->x * new_y;
+ new_size = sizeof (funcptr_t) * x * new_y;
if (table->mmd_funcs)
- table->mmd_funcs = mem_sys_realloc(table->mmd_funcs, new_size);
+ new_table = mem_sys_realloc(table->mmd_funcs, new_size);
else
- table->mmd_funcs = (funcptr_t *)mem_sys_allocate(new_size);
-
+ new_table = (funcptr_t *)mem_sys_allocate(new_size);
+
+ /* Initialize the newly allocated space with NULLs */
+ for (i = x * y; i < x * new_y; i++) {
+ new_table[i] = NULL;
+ }
+
+ table->mmd_funcs = new_table;
table->y = new_y;
}