From 2dc816125cd2cd62609c8d92fc34a8ba6f13e7ee Mon Sep 17 00:00:00 2001 From: "mccabe%netscape.com" Date: Sat, 17 Jul 1999 10:31:29 +0000 Subject: [PATCH] Fix to 9596. Change several allocations to behave safely when we're linking 0 interfaces. This also allows xpt_link to be linked against Electric Fence, which will doubtless discover other problems... Thanks to kherron@sgum.mci.com for the great patch! git-svn-id: svn://10.0.0.236/trunk@39856 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/typelib/xpt/tools/xpt_link.c | 60 +++++++++++----------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/mozilla/xpcom/typelib/xpt/tools/xpt_link.c b/mozilla/xpcom/typelib/xpt/tools/xpt_link.c index b67758f3d5f..08c2f858252 100644 --- a/mozilla/xpcom/typelib/xpt/tools/xpt_link.c +++ b/mozilla/xpcom/typelib/xpt/tools/xpt_link.c @@ -101,7 +101,7 @@ main(int argc, char **argv) XPTState *state; XPTCursor curs, *cursor = &curs; XPTHeader *header; - XPTInterfaceDirectoryEntry *newIDE, *IDE_array; + XPTInterfaceDirectoryEntry *IDE_array = NULL; XPTInterfaceDescriptor *id; XPTTypeDescriptor *td; XPTAnnotation *ann, *first_ann; @@ -109,7 +109,7 @@ main(int argc, char **argv) size_t flen = 0; char *head, *data, *whole; FILE *in, *out; - fixElement *newFix, *fix_array; + fixElement *fix_array = NULL; int i,j; int k = 0; @@ -171,40 +171,42 @@ main(int argc, char **argv) } totalNumberOfInterfaces += header->num_interfaces; - if (k == 0) { - IDE_array = XPT_CALLOC(totalNumberOfInterfaces * sizeof(XPTInterfaceDirectoryEntry)); - fix_array = XPT_CALLOC(totalNumberOfInterfaces * sizeof(fixElement)); - } else { - newIDE = XPT_REALLOC(IDE_array, totalNumberOfInterfaces * sizeof(XPTInterfaceDirectoryEntry)); - newFix = XPT_REALLOC(fix_array, totalNumberOfInterfaces * sizeof(fixElement)); - + if (header->num_interfaces > 0) { + XPTInterfaceDirectoryEntry *newIDE; + fixElement *newFix; + + newIDE = (XPTInterfaceDirectoryEntry *) + XPT_REALLOC(IDE_array, totalNumberOfInterfaces * sizeof(XPTInterfaceDirectoryEntry)); if (!newIDE) { perror("FAILED: XPT_REALLOC of IDE_array"); return 1; } - if (!newFix) { - perror("FAILED: XPT_REALLOC of newFix"); - return 1; - } IDE_array = newIDE; - fix_array = newFix; - } - - for (j=0; jnum_interfaces; j++) { - if (!copy_IDE(&header->interface_directory[j], - &IDE_array[k])) { - perror("FAILED: 1st copying of IDE"); + + newFix = (fixElement *) + XPT_REALLOC(fix_array, totalNumberOfInterfaces * sizeof(fixElement)); + if (!newFix) { + perror("FAILED: XPT_REALLOC of fix_array"); return 1; } - fix_array[k].iid = IDE_array[k].iid; - fix_array[k].name = IDE_array[k].name; - fix_array[k].file_num = i-2; - fix_array[k].interface_num = j+1; - fix_array[k].is_deleted = PR_FALSE; - fix_array[k].maps_to_file_num = i-2; - fix_array[k].maps_to_interface_num = j+1; - - k++; + fix_array = newFix; + + for (j=0; jnum_interfaces; j++) { + if (!copy_IDE(&header->interface_directory[j], + &IDE_array[k])) { + perror("FAILED: 1st copying of IDE"); + return 1; + } + fix_array[k].iid = IDE_array[k].iid; + fix_array[k].name = IDE_array[k].name; + fix_array[k].file_num = i-2; + fix_array[k].interface_num = j+1; + fix_array[k].is_deleted = PR_FALSE; + fix_array[k].maps_to_file_num = i-2; + fix_array[k].maps_to_interface_num = j+1; + + k++; + } } /* Copy the annotations.