bug-guile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] reducing uninitialized memory warnings


From: I.Sheldon
Subject: [PATCH] reducing uninitialized memory warnings
Date: Tue, 24 Sep 2002 19:10:52 +0100
User-agent: Gnus/5.090005 (Oort Gnus v0.05) XEmacs/21.4 (Common Lisp, i386-mandrake-linux)

When embedding guile I noticed there were quite a few uninitialized
memory read problems if it's run with a memory checker (e.g.,
purify, valgrind, etc.)

I imagine most of these are fine, e.g., just due to holes in
structures.  However, for me, it would be better to reduce these so
when guile is embedded, developers don't see warnings due to guile.

The following patch helps eliminate some of these warnings.

With a simple test of starting guile and then typing `(quit)', this
reduced the number of warnings I was getting from 19270 to 19014.  It
does this by ensuring the jmp_buf is fully initialized since,
otherwise, functions such as scm_mark_locations used to complain more
frequently (e.g., jmpbuf saved in coop-threads.c, then an
scm_mark_locations for each short for sizeof the jmpbuf struct, so
with holes in the structure it meant several read warnings).

* continuations.c ("scm_make_continuation"): added memset for jmpbuf
to reduce uninitialized memory warnings.
* coop-threads.c ("scm_threads_mark_stacks"): ditto
* gc-mark.c ("scm_mark_all"): ditto
* gc_os_dep.c ("GC_reset_fault_handler"): ditto
* throw.c ("scm_internal_catch"): ditto

Hope it's useful,
Ian.


Index: continuations.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/continuations.c,v
retrieving revision 1.45
diff -u -r1.45 continuations.c
--- continuations.c     4 Aug 2002 00:17:18 -0000       1.45
+++ continuations.c     24 Sep 2002 17:17:54 -0000
@@ -190,6 +190,7 @@
       return ret;
     }
 #else /* !__ia64__ */
+  memset (&continuation->jmpbuf, 0, sizeof continuation->jmpbuf);
   if (setjmp (continuation->jmpbuf))
     {
       SCM ret = continuation->throw_value;
Index: coop-threads.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/coop-threads.c,v
retrieving revision 1.35
diff -u -r1.35 coop-threads.c
--- coop-threads.c      1 Mar 2002 00:19:20 -0000       1.35
+++ coop-threads.c      24 Sep 2002 17:17:56 -0000
@@ -46,6 +46,10 @@
 #include "libguile/coop-threads.h"
 #include "libguile/root.h"
 
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
 /* A counter of the current number of threads */
 size_t scm_thread_count = 0;
 
@@ -105,6 +109,7 @@
           */
          SCM_FLUSH_REGISTER_WINDOWS;
          /* This assumes that all registers are saved into the jmp_buf */
+         memset (&scm_save_regs_gc_mark, 0, sizeof scm_save_regs_gc_mark);
          setjmp (scm_save_regs_gc_mark);
          scm_mark_locations ((SCM_STACKITEM *) scm_save_regs_gc_mark,
                              ((size_t) sizeof scm_save_regs_gc_mark
@@ -126,6 +131,7 @@
           */
          SCM_FLUSH_REGISTER_WINDOWS;
          /* This assumes that all registers are saved into the jmp_buf */
+         memset (&scm_save_regs_gc_mark, 0, sizeof scm_save_regs_gc_mark);
          setjmp (scm_save_regs_gc_mark);
          scm_mark_locations ((SCM_STACKITEM *) scm_save_regs_gc_mark,
                              ((size_t) sizeof scm_save_regs_gc_mark
Index: gc-mark.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/gc-mark.c,v
retrieving revision 1.4
diff -u -r1.4 gc-mark.c
--- gc-mark.c   8 Aug 2002 23:18:23 -0000       1.4
+++ gc-mark.c   24 Sep 2002 17:17:59 -0000
@@ -115,6 +115,7 @@
   /* Mark objects on the C stack. */
   SCM_FLUSH_REGISTER_WINDOWS;
   /* This assumes that all registers are saved into the jmp_buf */
+  memset (&scm_save_regs_gc_mark, 0, sizeof scm_save_regs_gc_mark);
   setjmp (scm_save_regs_gc_mark);
   scm_mark_locations ((SCM_STACKITEM *) scm_save_regs_gc_mark,
                      (   (size_t) (sizeof (SCM_STACKITEM) - 1 +
Index: gc_os_dep.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/gc_os_dep.c,v
retrieving revision 1.13
diff -u -r1.13 gc_os_dep.c
--- gc_os_dep.c 8 Jul 2002 23:41:00 -0000       1.13
+++ gc_os_dep.c 24 Sep 2002 17:18:07 -0000
@@ -1758,6 +1758,7 @@
 
 
        GC_setup_temporary_fault_handler();
+       memset (&GC_jmp_buf, 0, sizeof GC_jmp_buf);
        if (setjmp(GC_jmp_buf) == 0) {
            result = (ptr_t)(((word)(p))
                              & ~(MIN_PAGE_SIZE-1));
Index: throw.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/throw.c,v
retrieving revision 1.91
diff -u -r1.91 throw.c
--- throw.c     20 Jul 2002 14:08:34 -0000      1.91
+++ throw.c     24 Sep 2002 17:18:10 -0000
@@ -63,6 +63,10 @@
 #include "libguile/validate.h"
 #include "libguile/throw.h"
 
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
 
 /* the jump buffer data structure */
 static scm_t_bits tc16_jmpbuffer;
@@ -182,6 +186,7 @@
 #ifdef DEBUG_EXTENSIONS
   SCM_SETJBDFRAME(jmpbuf, scm_last_debug_frame);
 #endif
+  memset (&jbr.buf, 0, sizeof jbr.buf);
   if (setjmp (jbr.buf))
     {
       SCM throw_tag;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]