Mercurial > hg > xemacs-beta
changeset 3462:6c7605dfcf07
[xemacs-hg @ 2006-06-19 18:19:33 by james]
Fix various problems found by static checkers: use of uninitialized values,
dereferencing pointers before checking whether they are NULL, memory leaks,
and incomplete checking of return values. <m3k67gpyhk.fsf@jerrypc.cs.usu.edu>
author | james |
---|---|
date | Mon, 19 Jun 2006 18:19:38 +0000 |
parents | fd2936bbfc5f |
children | 3aab51033467 |
files | lwlib/ChangeLog lwlib/lwlib-Xlw.c lwlib/xlwmenu.c src/ChangeLog src/dgif_lib.c src/fileio.c src/input-method-xlib.c src/md5.c src/nas.c src/scrollbar-x.c src/text.c src/vdb-posix.c src/window.c |
diffstat | 13 files changed, 62 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/lwlib/ChangeLog Mon Jun 19 18:10:19 2006 +0000 +++ b/lwlib/ChangeLog Mon Jun 19 18:19:38 2006 +0000 @@ -1,3 +1,10 @@ +2006-06-16 Jerry James <james@xemacs.org> + + * lwlib-Xlw.c (xlw_scrollbar_callback): Do not dereference + instance before checking whether it is NULL. + * xlwmenu.c (xlw_map_menu): Prevent uninitialized access to root + and waste. + 2006-05-16 Stephen J. Turnbull <stephen@xemacs.org> * XEmacs 21.5.27 "fiddleheads" is released.
--- a/lwlib/lwlib-Xlw.c Mon Jun 19 18:10:19 2006 +0000 +++ b/lwlib/lwlib-Xlw.c Mon Jun 19 18:19:38 2006 +0000 @@ -158,13 +158,13 @@ XlwScrollBarCallbackStruct *data = (XlwScrollBarCallbackStruct *) call_data; scroll_event event_data; - scrollbar_values *val = - (scrollbar_values *) instance->info->val->scrollbar_data; + scrollbar_values *val; double percent; if (!instance || widget->core.being_destroyed) return; + val = (scrollbar_values *) instance->info->val->scrollbar_data; id = instance->info->id; percent = (double) (data->value - 1) / (double) (INT_MAX - 1);
--- a/lwlib/xlwmenu.c Mon Jun 19 18:10:19 2006 +0000 +++ b/lwlib/xlwmenu.c Mon Jun 19 18:19:38 2006 +0000 @@ -3630,8 +3630,8 @@ if (!mw->menu.pointer_grabbed) { XWindowAttributes ret; - Window parent,root; - Window *waste; + Window parent,root = 0UL; + Window *waste = NULL; unsigned int num_waste; lw_menu_active = True;
--- a/src/ChangeLog Mon Jun 19 18:10:19 2006 +0000 +++ b/src/ChangeLog Mon Jun 19 18:19:38 2006 +0000 @@ -1,3 +1,21 @@ +2006-06-16 Jerry James <james@xemacs.org> + + * dgif_lib.c (DGifCloseFile): Do not dereference GifFile before + checking if it is NULL. Also fix a memory leak. + * fileio.c (Finsert_file_contents_internal): Remove dead code. + * input-method-xlib.c (XIM_SetGeometry): Do not dereference f or + xic before checking if they are NULL. + * md5.c (Fmd5): Check whether Lstream_read encountered an error. + * nas.c (Err): Fix a memory leak. + * scrollbar-x.c (x_free_scrollbar_instance): Do not dereference + instance->scrollbar_data before checking if it is NULL. + * text.c (eicmp_1): Move assertions to before the point where they + must be true for correctness. + * vdb-posix.c (vdb_fault_handler): Guard against a return from + ABORT(). + * window.c (change_window_height): Skip always true comparison in + the expansion of CURCHARSIZE. + 2006-06-16 Jerry James <james@xemacs.org> * alloc.c: Don't add MODULE_DEFINABLE_TYPE_COUNT to
--- a/src/dgif_lib.c Mon Jun 19 18:10:19 2006 +0000 +++ b/src/dgif_lib.c Mon Jun 19 18:19:38 2006 +0000 @@ -366,10 +366,11 @@ ******************************************************************************/ int DGifCloseFile(GifFileType *GifFile) { - GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private; + GifFilePrivateType *Private; if (GifFile == NULL) return -1; + Private = (GifFilePrivateType *)GifFile->Private; if (!IS_READABLE(Private)) { /* This file was NOT open for reading: */ @@ -929,8 +930,10 @@ return((ColorMapObject *)NULL); Object->Colors = (GifColorType *)calloc(ColorCount, sizeof(GifColorType)); - if (Object->Colors == (GifColorType *)NULL) + if (Object->Colors == (GifColorType *)NULL) { + free(Object); return((ColorMapObject *)NULL); + } Object->ColorCount = ColorCount; Object->BitsPerPixel = BitSize(ColorCount);
--- a/src/fileio.c Mon Jun 19 18:10:19 2006 +0000 +++ b/src/fileio.c Mon Jun 19 18:19:38 2006 +0000 @@ -2855,7 +2855,6 @@ if (qxe_stat (XSTRING_DATA (filename), &st) < 0) { - if (fd >= 0) retry_close (fd); badopen: if (NILP (visit)) report_file_error ("Opening input file", filename);
--- a/src/input-method-xlib.c Mon Jun 19 18:10:19 2006 +0000 +++ b/src/input-method-xlib.c Mon Jun 19 18:19:38 2006 +0000 @@ -384,13 +384,18 @@ void XIM_SetGeometry (struct frame *f) { - XIC xic = FRAME_X_XIC (f); - XIMStyle style = FRAME_X_XIC_STYLE (f); + XIC xic; + XIMStyle style; XRectangle area; - if (!xic || !f) + if (!f) return; + xic = FRAME_X_XIC (f); + if (!xic) + return; + + style = FRAME_X_XIC_STYLE (f); if (style & XIMStatusArea) { /* Place Status Area in bottom right corner */
--- a/src/md5.c Mon Jun 19 18:10:19 2006 +0000 +++ b/src/md5.c Mon Jun 19 18:19:38 2006 +0000 @@ -556,7 +556,7 @@ Ibyte tempbuf[1024]; /* some random amount */ Bytecount size_in_bytes = Lstream_read (XLSTREAM (instream), tempbuf, sizeof (tempbuf)); - if (!size_in_bytes) + if (size_in_bytes <= 0) break; /* Process the bytes. */
--- a/src/nas.c Mon Jun 19 18:10:19 2006 +0000 +++ b/src/nas.c Mon Jun 19 18:19:38 2006 +0000 @@ -728,7 +728,7 @@ /* Stuff taken from wave.c from NAS. Just like snd files, NAS can't read wave data from memory, so these functions do that for us. */ -#define Err() { return NULL; } +#define Err() { free(wi); return NULL; } #define readFourcc(_f) dread(_f, sizeof(RIFF_FOURCC), 1) #define cmpID(_x, _y) \ strncmp((CBinbyte *) (_x), (CBinbyte *) (_y), sizeof(RIFF_FOURCC))
--- a/src/scrollbar-x.c Mon Jun 19 18:10:19 2006 +0000 +++ b/src/scrollbar-x.c Mon Jun 19 18:19:38 2006 +0000 @@ -72,19 +72,21 @@ static void x_free_scrollbar_instance (struct scrollbar_instance *instance) { - if (SCROLLBAR_X_NAME (instance)) - xfree (SCROLLBAR_X_NAME (instance), char *); - - if (SCROLLBAR_X_WIDGET (instance)) + if (instance->scrollbar_data) { - if (XtIsManaged (SCROLLBAR_X_WIDGET (instance))) - XtUnmanageChild (SCROLLBAR_X_WIDGET (instance)); + if (SCROLLBAR_X_NAME (instance)) + xfree (SCROLLBAR_X_NAME (instance), char *); - lw_destroy_all_widgets (SCROLLBAR_X_ID (instance)); - } + if (SCROLLBAR_X_WIDGET (instance)) + { + if (XtIsManaged (SCROLLBAR_X_WIDGET (instance))) + XtUnmanageChild (SCROLLBAR_X_WIDGET (instance)); - if (instance->scrollbar_data) - xfree (instance->scrollbar_data, void *); + lw_destroy_all_widgets (SCROLLBAR_X_ID (instance)); + } + + xfree (instance->scrollbar_data, void *); + } } /* A device method. */
--- a/src/text.c Mon Jun 19 18:10:19 2006 +0000 +++ b/src/text.c Mon Jun 19 18:19:38 2006 +0000 @@ -2138,7 +2138,11 @@ Bytecount len, Charcount charlen, const Ibyte *data, const Eistring *ei2, int is_ascii, int fold_case) { + assert ((data == 0) != (ei == 0)); + assert ((is_ascii != 0) == (data != 0)); + assert (fold_case >= 0 && fold_case <= 2); assert ((off < 0) != (charoff < 0)); + if (off < 0) { off = charcount_to_bytecount (ei->data_, charoff); @@ -2152,9 +2156,6 @@ assert (off >= 0 && off <= ei->bytelen_); assert (len >= 0 && off + len <= ei->bytelen_); - assert ((data == 0) != (ei == 0)); - assert ((is_ascii != 0) == (data != 0)); - assert (fold_case >= 0 && fold_case <= 2); { Bytecount dstlen;
--- a/src/vdb-posix.c Mon Jun 19 18:10:19 2006 +0000 +++ b/src/vdb-posix.c Mon Jun 19 18:19:38 2006 +0000 @@ -73,7 +73,7 @@ } else /* default sigsegv handler */ { - char *signal_name; + char *signal_name = ""; if (signum == SIGSEGV) signal_name = "SIGSEGV"; else if (signum == SIGBUS)
--- a/src/window.c Mon Jun 19 18:10:19 2006 +0000 +++ b/src/window.c Mon Jun 19 18:19:38 2006 +0000 @@ -4380,7 +4380,7 @@ { int new_pixsize; sizep = &CURSIZE (w); - dim = CURCHARSIZE (w); + dim = window_char_width (w, 0); new_pixsize = inpixels?(*sizep + delta):(dim+delta); set_window_pixsize (window, new_pixsize, 0, 0); return;