unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: is+guile@kaidea.freeserve.co.uk (I.Sheldon)
Subject: [PATCH] reducing uninitialized memory warnings
Date: Tue, 24 Sep 2002 19:10:52 +0100	[thread overview]
Message-ID: <m2ptv3jm1f.fsf@seth.kaidea.freeserve.co.uk> (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


             reply	other threads:[~2002-09-24 18:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-24 18:10 I.Sheldon [this message]
2002-10-03 18:03 ` [PATCH] reducing uninitialized memory warnings Marius Vollmer
2002-10-03 21:28   ` Neil Jerram
2002-10-03 22:23     ` Marius Vollmer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2ptv3jm1f.fsf@seth.kaidea.freeserve.co.uk \
    --to=is+guile@kaidea.freeserve.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).