diff options
| author | Paul Eggert | 2011-08-04 19:15:35 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-08-04 19:15:35 -0700 |
| commit | 0065d05491ce5981ea20896bb26d21dcd31e6769 (patch) | |
| tree | 13240167319d4a99ab5eacae4a883258eb2d28de /src/ftfont.c | |
| parent | 18ab493650d648ab8dca651ea2698861f926e895 (diff) | |
| download | emacs-0065d05491ce5981ea20896bb26d21dcd31e6769.tar.gz emacs-0065d05491ce5981ea20896bb26d21dcd31e6769.zip | |
Adjust in response to jan.h.d's comments.
See, for example <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9196#26>.
Diffstat (limited to 'src/ftfont.c')
| -rw-r--r-- | src/ftfont.c | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/src/ftfont.c b/src/ftfont.c index 551006eef94..5b95e2b2f08 100644 --- a/src/ftfont.c +++ b/src/ftfont.c | |||
| @@ -1764,18 +1764,10 @@ static OTF_GlyphString otf_gstring; | |||
| 1764 | static void | 1764 | static void |
| 1765 | setup_otf_gstring (int size) | 1765 | setup_otf_gstring (int size) |
| 1766 | { | 1766 | { |
| 1767 | if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (OTF_Glyph) < size) | 1767 | if (otf_gstring.size < size) |
| 1768 | memory_full (SIZE_MAX); | ||
| 1769 | |||
| 1770 | if (otf_gstring.size == 0) | ||
| 1771 | { | 1768 | { |
| 1772 | otf_gstring.glyphs = (OTF_Glyph *) xmalloc (sizeof (OTF_Glyph) * size); | 1769 | otf_gstring.glyphs = xnrealloc (otf_gstring.glyphs, |
| 1773 | otf_gstring.size = size; | 1770 | size, sizeof (OTF_Glyph)); |
| 1774 | } | ||
| 1775 | else if (otf_gstring.size < size) | ||
| 1776 | { | ||
| 1777 | otf_gstring.glyphs = xrealloc (otf_gstring.glyphs, | ||
| 1778 | sizeof (OTF_Glyph) * size); | ||
| 1779 | otf_gstring.size = size; | 1771 | otf_gstring.size = size; |
| 1780 | } | 1772 | } |
| 1781 | otf_gstring.used = size; | 1773 | otf_gstring.used = size; |
| @@ -2396,8 +2388,6 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font, | |||
| 2396 | struct MFLTFontFT flt_font_ft; | 2388 | struct MFLTFontFT flt_font_ft; |
| 2397 | MFLT *flt = NULL; | 2389 | MFLT *flt = NULL; |
| 2398 | int with_variation_selector = 0; | 2390 | int with_variation_selector = 0; |
| 2399 | int allocated_max = min (INT_MAX, | ||
| 2400 | min (PTRDIFF_MAX, SIZE_MAX) / sizeof (MFLTGlyph)); | ||
| 2401 | 2391 | ||
| 2402 | if (! m17n_flt_initialized) | 2392 | if (! m17n_flt_initialized) |
| 2403 | { | 2393 | { |
| @@ -2453,20 +2443,19 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font, | |||
| 2453 | } | 2443 | } |
| 2454 | } | 2444 | } |
| 2455 | 2445 | ||
| 2456 | if (allocated_max / 2 < len) | 2446 | if (INT_MAX / 2 < len) |
| 2457 | memory_full (SIZE_MAX); | 2447 | memory_full (SIZE_MAX); |
| 2458 | 2448 | ||
| 2459 | if (gstring.allocated == 0) | 2449 | if (gstring.allocated == 0) |
| 2460 | { | 2450 | { |
| 2461 | gstring.allocated = len * 2; | ||
| 2462 | gstring.glyph_size = sizeof (MFLTGlyph); | 2451 | gstring.glyph_size = sizeof (MFLTGlyph); |
| 2463 | gstring.glyphs = xmalloc (sizeof (MFLTGlyph) * gstring.allocated); | 2452 | gstring.glyphs = xnmalloc (len * 2, sizeof (MFLTGlyph)); |
| 2453 | gstring.allocated = len * 2; | ||
| 2464 | } | 2454 | } |
| 2465 | else if (gstring.allocated < len * 2) | 2455 | else if (gstring.allocated < len * 2) |
| 2466 | { | 2456 | { |
| 2457 | gstring.glyphs = xnrealloc (gstring.glyphs, len * 2, sizeof (MFLTGlyph)); | ||
| 2467 | gstring.allocated = len * 2; | 2458 | gstring.allocated = len * 2; |
| 2468 | gstring.glyphs = xrealloc (gstring.glyphs, | ||
| 2469 | sizeof (MFLTGlyph) * gstring.allocated); | ||
| 2470 | } | 2459 | } |
| 2471 | memset (gstring.glyphs, 0, sizeof (MFLTGlyph) * len); | 2460 | memset (gstring.glyphs, 0, sizeof (MFLTGlyph) * len); |
| 2472 | for (i = 0; i < len; i++) | 2461 | for (i = 0; i < len; i++) |
| @@ -2515,11 +2504,11 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font, | |||
| 2515 | int result = mflt_run (&gstring, 0, len, &flt_font_ft.flt_font, flt); | 2504 | int result = mflt_run (&gstring, 0, len, &flt_font_ft.flt_font, flt); |
| 2516 | if (result != -2) | 2505 | if (result != -2) |
| 2517 | break; | 2506 | break; |
| 2518 | if (allocated_max / 2 < gstring.allocated) | 2507 | if (INT_MAX / 2 < gstring.allocated) |
| 2519 | memory_full (SIZE_MAX); | 2508 | memory_full (SIZE_MAX); |
| 2520 | gstring.allocated += gstring.allocated; | 2509 | gstring.glyphs = xnrealloc (gstring.glyphs, |
| 2521 | gstring.glyphs = xrealloc (gstring.glyphs, | 2510 | gstring.allocated, 2 * sizeof (MFLTGlyph)); |
| 2522 | sizeof (MFLTGlyph) * gstring.allocated); | 2511 | gstring.allocated *= 2; |
| 2523 | } | 2512 | } |
| 2524 | if (gstring.used > LGSTRING_GLYPH_LEN (lgstring)) | 2513 | if (gstring.used > LGSTRING_GLYPH_LEN (lgstring)) |
| 2525 | return Qnil; | 2514 | return Qnil; |