comparison src/ftfont.c @ 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 941b1ddcbe2e
children 1e63d004a073
comparison
equal deleted inserted replaced
103555:e3e672080345 103556:246d16550b8d
1698 static void 1698 static void
1699 setup_otf_gstring (int size) 1699 setup_otf_gstring (int size)
1700 { 1700 {
1701 if (otf_gstring.size == 0) 1701 if (otf_gstring.size == 0)
1702 { 1702 {
1703 otf_gstring.glyphs = (OTF_Glyph *) malloc (sizeof (OTF_Glyph) * size); 1703 otf_gstring.glyphs = (OTF_Glyph *) xmalloc (sizeof (OTF_Glyph) * size);
1704 otf_gstring.size = size; 1704 otf_gstring.size = size;
1705 } 1705 }
1706 else if (otf_gstring.size < size) 1706 else if (otf_gstring.size < size)
1707 { 1707 {
1708 otf_gstring.glyphs = (OTF_Glyph *) realloc (otf_gstring.glyphs, 1708 otf_gstring.glyphs = xrealloc (otf_gstring.glyphs,
1709 sizeof (OTF_Glyph) * size); 1709 sizeof (OTF_Glyph) * size);
1710 otf_gstring.size = size; 1710 otf_gstring.size = size;
1711 } 1711 }
1712 otf_gstring.used = size; 1712 otf_gstring.used = size;
1713 memset (otf_gstring.glyphs, 0, sizeof (OTF_Glyph) * size); 1713 memset (otf_gstring.glyphs, 0, sizeof (OTF_Glyph) * size);
1714 } 1714 }
2035 2035
2036 if (gstring.allocated == 0) 2036 if (gstring.allocated == 0)
2037 { 2037 {
2038 gstring.allocated = len * 2; 2038 gstring.allocated = len * 2;
2039 gstring.glyph_size = sizeof (MFLTGlyph); 2039 gstring.glyph_size = sizeof (MFLTGlyph);
2040 gstring.glyphs = malloc (sizeof (MFLTGlyph) * gstring.allocated); 2040 gstring.glyphs = xmalloc (sizeof (MFLTGlyph) * gstring.allocated);
2041 } 2041 }
2042 else if (gstring.allocated < len * 2) 2042 else if (gstring.allocated < len * 2)
2043 { 2043 {
2044 gstring.allocated = len * 2; 2044 gstring.allocated = len * 2;
2045 gstring.glyphs = realloc (gstring.glyphs, 2045 gstring.glyphs = xrealloc (gstring.glyphs,
2046 sizeof (MFLTGlyph) * gstring.allocated); 2046 sizeof (MFLTGlyph) * gstring.allocated);
2047 } 2047 }
2048 memset (gstring.glyphs, 0, sizeof (MFLTGlyph) * len); 2048 memset (gstring.glyphs, 0, sizeof (MFLTGlyph) * len);
2049 for (i = 0; i < len; i++) 2049 for (i = 0; i < len; i++)
2050 { 2050 {
2051 Lisp_Object g = LGSTRING_GLYPH (lgstring, i); 2051 Lisp_Object g = LGSTRING_GLYPH (lgstring, i);
2090 { 2090 {
2091 int result = mflt_run (&gstring, 0, len, &flt_font_ft.flt_font, flt); 2091 int result = mflt_run (&gstring, 0, len, &flt_font_ft.flt_font, flt);
2092 if (result != -2) 2092 if (result != -2)
2093 break; 2093 break;
2094 gstring.allocated += gstring.allocated; 2094 gstring.allocated += gstring.allocated;
2095 gstring.glyphs = realloc (gstring.glyphs, 2095 gstring.glyphs = xrealloc (gstring.glyphs,
2096 sizeof (MFLTGlyph) * gstring.allocated); 2096 sizeof (MFLTGlyph) * gstring.allocated);
2097 } 2097 }
2098 if (gstring.used > LGSTRING_GLYPH_LEN (lgstring)) 2098 if (gstring.used > LGSTRING_GLYPH_LEN (lgstring))
2099 return Qnil; 2099 return Qnil;
2100 for (i = 0; i < gstring.used; i++) 2100 for (i = 0; i < gstring.used; i++)
2101 { 2101 {