aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJim Meyering2009-06-23 06:49:20 +0000
committerJim Meyering2009-06-23 06:49:20 +0000
commitc6da7cd2b63cc9094d690b74875bf8609b5c0107 (patch)
tree4c6731024ab0f50692ceb0b848492a3b77b1bdcf /src
parentf5f20f6c6718e08c1c8c9140466c7eb5811fe467 (diff)
downloademacs-c6da7cd2b63cc9094d690b74875bf8609b5c0107.tar.gz
emacs-c6da7cd2b63cc9094d690b74875bf8609b5c0107.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog7
-rw-r--r--src/ftfont.c16
2 files changed, 15 insertions, 8 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index a0f2650445a..9e1830e4d4a 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
12009-06-23 Jim Meyering <meyering@redhat.com>
2
3 Don't dereference NULL upon failed malloc and realloc
4 * src/ftfont.c (setup_otf_gstring, ftfont_shape_by_flt): Use xmalloc
5 and xrealloc (not malloc and realloc), so subsequent heap pointer
6 dereferences are guaranteed to be valid.
7
12009-06-23 Kenichi Handa <handa@m17n.org> 82009-06-23 Kenichi Handa <handa@m17n.org>
2 9
3 * emacs.c (main): Call init_font (). 10 * emacs.c (main): Call init_font ().
diff --git a/src/ftfont.c b/src/ftfont.c
index 695579a05f8..70c1797dce0 100644
--- a/src/ftfont.c
+++ b/src/ftfont.c
@@ -1700,13 +1700,13 @@ 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;
@@ -2037,13 +2037,13 @@ ftfont_shape_by_flt (lgstring, font, ft_face, otf)
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++)
@@ -2092,8 +2092,8 @@ ftfont_shape_by_flt (lgstring, font, ft_face, otf)
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;