changeset 103556:246d16550b8d

Don't dereference NULL upon failed malloc and realloc. * src/ftfont.c (setup_otf_gstring, ftfont_shape_by_flt): Use xmalloc and xrealloc (not malloc and realloc), so subsequent heap pointer dereferences are guaranteed to be valid.
author Jim Meyering <jim@meyering.net>
date Tue, 23 Jun 2009 06:49:20 +0000
parents e3e672080345
children f52eb7cf1c20
files src/ChangeLog src/ftfont.c
diffstat 2 files changed, 15 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Jun 23 06:45:39 2009 +0000
+++ b/src/ChangeLog	Tue Jun 23 06:49:20 2009 +0000
@@ -1,3 +1,10 @@
+2009-06-23  Jim Meyering  <meyering@redhat.com>
+
+	Don't dereference NULL upon failed malloc and realloc
+	* src/ftfont.c (setup_otf_gstring, ftfont_shape_by_flt): Use xmalloc
+	and xrealloc (not malloc and realloc), so subsequent heap pointer
+	dereferences are guaranteed to be valid.
+
 2009-06-23  Kenichi Handa  <handa@m17n.org>
 
 	* emacs.c (main): Call init_font ().
--- a/src/ftfont.c	Tue Jun 23 06:45:39 2009 +0000
+++ b/src/ftfont.c	Tue Jun 23 06:49:20 2009 +0000
@@ -1700,13 +1700,13 @@
 {
   if (otf_gstring.size == 0)
     {
-      otf_gstring.glyphs = (OTF_Glyph *) malloc (sizeof (OTF_Glyph) * size);
+      otf_gstring.glyphs = (OTF_Glyph *) xmalloc (sizeof (OTF_Glyph) * size);
       otf_gstring.size = size;
     }
   else if (otf_gstring.size < size)
     {
-      otf_gstring.glyphs = (OTF_Glyph *) realloc (otf_gstring.glyphs,
-						  sizeof (OTF_Glyph) * size);
+      otf_gstring.glyphs = xrealloc (otf_gstring.glyphs,
+				     sizeof (OTF_Glyph) * size);
       otf_gstring.size = size;
     }
   otf_gstring.used = size;
@@ -2037,13 +2037,13 @@
     {
       gstring.allocated = len * 2;
       gstring.glyph_size = sizeof (MFLTGlyph);
-      gstring.glyphs = malloc (sizeof (MFLTGlyph) * gstring.allocated);
+      gstring.glyphs = xmalloc (sizeof (MFLTGlyph) * gstring.allocated);
     }
   else if (gstring.allocated < len * 2)
     {
       gstring.allocated = len * 2;
-      gstring.glyphs = realloc (gstring.glyphs,
-				sizeof (MFLTGlyph) * gstring.allocated);
+      gstring.glyphs = xrealloc (gstring.glyphs,
+				 sizeof (MFLTGlyph) * gstring.allocated);
     }
   memset (gstring.glyphs, 0, sizeof (MFLTGlyph) * len);
   for (i = 0; i < len; i++)
@@ -2092,8 +2092,8 @@
       if (result != -2)
 	break;
       gstring.allocated += gstring.allocated;
-      gstring.glyphs = realloc (gstring.glyphs,
-				sizeof (MFLTGlyph) * gstring.allocated);
+      gstring.glyphs = xrealloc (gstring.glyphs,
+				 sizeof (MFLTGlyph) * gstring.allocated);
     }
   if (gstring.used > LGSTRING_GLYPH_LEN (lgstring))
     return Qnil;