unicode-internal-commit: fix crash due to attempt to realloc dumped memory

Ben Wing ben at xemacs.org
Wed Mar 31 01:00:17 EDT 2010


changeset:   5348:984e757cfe03
branch:      ben-unicode-internal
user:        Ben Wing <ben at xemacs.org>
date:        Mon Mar 29 16:03:02 2010 -0500
files:       src/ChangeLog src/unicode.c
description:
fix crash due to attempt to realloc dumped memory

-------------------- ChangeLog entries follow: --------------------

src/ChangeLog addition:

2010-03-29  Ben Wing  <ben at xemacs.org>

	* unicode.c (ensure_to_unicode_holds_range):
	If memory is dumped, allocate a new block and copy the existing one,
	rather than trying to realloc.


diff -r 83670f35e27b -r 984e757cfe03 src/ChangeLog
--- a/src/ChangeLog	Mon Mar 29 15:57:53 2010 -0500
+++ b/src/ChangeLog	Mon Mar 29 16:03:02 2010 -0500
@@ -1,3 +1,9 @@
+2010-03-29  Ben Wing  <ben at xemacs.org>
+
+	* unicode.c (ensure_to_unicode_holds_range):
+	If memory is dumped, allocate a new block and copy the existing one,
+	rather than trying to realloc.
+
 2010-03-29  Ben Wing  <ben at xemacs.org>
 
 	* abbrev.c:
diff -r 83670f35e27b -r 984e757cfe03 src/unicode.c
--- a/src/unicode.c	Mon Mar 29 15:57:53 2010 -0500
+++ b/src/unicode.c	Mon Mar 29 16:03:02 2010 -0500
@@ -950,6 +950,7 @@
        "Past max" means 1+max; essentially, [NEW_MIN, NEW_PAST_MAX) is
        a half-open interval. */
     int new_min, new_past_max;
+    Bytecount new_size;
     int existing; /* Table already exists or not? */
     to_unicode_base *to_table = *store_to_table;
     int i;
@@ -987,10 +988,15 @@
 	  }
 
 	/* Realloc */
-	to_table =
-	  (to_unicode_base *)
-	  xrealloc (to_table,
-		    needed_sizeof_to_unicode_base (new_past_max - new_min));
+	new_size = needed_sizeof_to_unicode_base (new_past_max - new_min);
+	if (DUMPEDP (to_table))
+	  {
+	    to_unicode_base *new_to_table = xmalloc (new_size);
+	    memcpy (new_to_table, to_table, sizeof_to_unicode_base (to_table));
+	    to_table = new_to_table;
+	  }
+	else
+	  to_table = (to_unicode_base *)  xrealloc (to_table, new_size);
 
 	/* We need to fill in any newly created slots with BADVAL_TO_TABLE.
 	   We also have to preserve existing values and may need to move



More information about the XEmacs-Patches mailing list