unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] reducing uninitialized memory warnings
@ 2002-09-24 18:10 I.Sheldon
  2002-10-03 18:03 ` Marius Vollmer
  0 siblings, 1 reply; 4+ messages in thread
From: I.Sheldon @ 2002-09-24 18:10 UTC (permalink / raw)


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
+
 \f
 /* 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;



_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] reducing uninitialized memory warnings
  2002-09-24 18:10 [PATCH] reducing uninitialized memory warnings I.Sheldon
@ 2002-10-03 18:03 ` Marius Vollmer
  2002-10-03 21:28   ` Neil Jerram
  0 siblings, 1 reply; 4+ messages in thread
From: Marius Vollmer @ 2002-10-03 18:03 UTC (permalink / raw)
  Cc: bug-guile

is+guile@kaidea.freeserve.co.uk (I.Sheldon) writes:

> With a simple test of starting guile and then typing `(quit)', this
> reduced the number of warnings I was getting from 19270 to 19014.

Since this reduction is so small, I'm inclined not to apply your
patch.  What do others say?

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] reducing uninitialized memory warnings
  2002-10-03 18:03 ` Marius Vollmer
@ 2002-10-03 21:28   ` Neil Jerram
  2002-10-03 22:23     ` Marius Vollmer
  0 siblings, 1 reply; 4+ messages in thread
From: Neil Jerram @ 2002-10-03 21:28 UTC (permalink / raw)
  Cc: is+guile, bug-guile

>>>>> "Marius" == Marius Vollmer <mvo@zagadka.ping.de> writes:

    Marius> is+guile@kaidea.freeserve.co.uk (I.Sheldon) writes:
    >> With a simple test of starting guile and then typing `(quit)', this
    >> reduced the number of warnings I was getting from 19270 to 19014.

    Marius> Since this reduction is so small, I'm inclined not to
    Marius> apply your patch.  What do others say?

Do the warnings indicate real problems, or are they false positives?
If real, we should fix them; if false, we shouldn't, because the fix
will generally impact performance, and instead we should send a report
to valgrind.

        Neil



_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] reducing uninitialized memory warnings
  2002-10-03 21:28   ` Neil Jerram
@ 2002-10-03 22:23     ` Marius Vollmer
  0 siblings, 0 replies; 4+ messages in thread
From: Marius Vollmer @ 2002-10-03 22:23 UTC (permalink / raw)
  Cc: is+guile, bug-guile

Neil Jerram <neil@ossau.uklinux.net> writes:

>     Marius> Since this reduction is so small, I'm inclined not to
>     Marius> apply your patch.  What do others say?
> 
> Do the warnings indicate real problems, or are they false positives?
> If real, we should fix them; if false, we shouldn't, because the fix
> will generally impact performance, and instead we should send a report
> to valgrind.

The way I understand it, they are false positives.  The warnings come
when Guile is conservatively marking pointers in a region that hasn't
been fully initialized.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-10-03 22:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-24 18:10 [PATCH] reducing uninitialized memory warnings I.Sheldon
2002-10-03 18:03 ` Marius Vollmer
2002-10-03 21:28   ` Neil Jerram
2002-10-03 22:23     ` Marius Vollmer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).