aboutsummaryrefslogtreecommitdiffstats
path: root/src/composite.c
diff options
context:
space:
mode:
authorPaul Eggert2011-08-04 19:15:35 -0700
committerPaul Eggert2011-08-04 19:15:35 -0700
commit0065d05491ce5981ea20896bb26d21dcd31e6769 (patch)
tree13240167319d4a99ab5eacae4a883258eb2d28de /src/composite.c
parent18ab493650d648ab8dca651ea2698861f926e895 (diff)
downloademacs-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/composite.c')
-rw-r--r--src/composite.c39
1 files changed, 12 insertions, 27 deletions
diff --git a/src/composite.c b/src/composite.c
index 4ae1d6ebb68..738fcd3774c 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -186,13 +186,14 @@ get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars,
186 EMACS_INT i; 186 EMACS_INT i;
187 int ch; 187 int ch;
188 188
189 /* Maximum length of a string of glyphs. XftGlyphExtents limits this 189 /* Maximum length of a string of glyphs. XftGlyphExtents limits
190 to INT_MAX, and Emacs may limit it further. */ 190 this to INT_MAX, and Emacs limits it further. Divide INT_MAX - 1
191 by 2 because x_produce_glyphs computes glyph_len * 2 + 1. Divide
192 the size by MAX_MULTIBYTE_LENGTH because encode_terminal_code
193 multiplies glyph_len by MAX_MULTIBYTE_LENGTH. */
191 enum { 194 enum {
192 glyph_len_max = 195 GLYPH_LEN_MAX = min ((INT_MAX - 1) / 2,
193 min (INT_MAX, 196 min (PTRDIFF_MAX, SIZE_MAX) / MAX_MULTIBYTE_LENGTH)
194 (min (PTRDIFF_MAX, SIZE_MAX)
195 / max (MAX_MULTIBYTE_LENGTH, 2 * sizeof (short))))
196 }; 197 };
197 198
198 /* PROP should be 199 /* PROP should be
@@ -268,25 +269,9 @@ get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars,
268 /* This composition is a new one. We must register it. */ 269 /* This composition is a new one. We must register it. */
269 270
270 /* Check if we have sufficient memory to store this information. */ 271 /* Check if we have sufficient memory to store this information. */
271 if (composition_table_size == 0) 272 if (composition_table_size <= n_compositions)
272 { 273 composition_table = xpalloc (composition_table, &composition_table_size,
273 composition_table 274 1, -1, sizeof *composition_table);
274 = (struct composition **) xmalloc (sizeof (composition_table[0]) * 256);
275 composition_table_size = 256;
276 }
277 else if (composition_table_size <= n_compositions)
278 {
279 if ((min (MOST_POSITIVE_FIXNUM,
280 min (PTRDIFF_MAX, SIZE_MAX) / sizeof composition_table[0])
281 - 256)
282 < composition_table_size)
283 memory_full (SIZE_MAX);
284 composition_table
285 = (struct composition **) xrealloc (composition_table,
286 sizeof (composition_table[0])
287 * (composition_table_size + 256));
288 composition_table_size += 256;
289 }
290 275
291 key_contents = XVECTOR (key)->contents; 276 key_contents = XVECTOR (key)->contents;
292 277
@@ -340,7 +325,7 @@ get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars,
340 ? (ASIZE (key) + 1) / 2 325 ? (ASIZE (key) + 1) / 2
341 : ASIZE (key)); 326 : ASIZE (key));
342 327
343 if (glyph_len_max < glyph_len) 328 if (GLYPH_LEN_MAX < glyph_len)
344 memory_full (SIZE_MAX); 329 memory_full (SIZE_MAX);
345 330
346 /* Register the composition in composition_table. */ 331 /* Register the composition in composition_table. */
@@ -349,7 +334,7 @@ get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars,
349 cmp->method = method; 334 cmp->method = method;
350 cmp->hash_index = hash_index; 335 cmp->hash_index = hash_index;
351 cmp->glyph_len = glyph_len; 336 cmp->glyph_len = glyph_len;
352 cmp->offsets = (short *) xmalloc (sizeof (short) * glyph_len * 2); 337 cmp->offsets = xnmalloc (glyph_len, 2 * sizeof *cmp->offsets);
353 cmp->font = NULL; 338 cmp->font = NULL;
354 339
355 if (cmp->method != COMPOSITION_WITH_RULE_ALTCHARS) 340 if (cmp->method != COMPOSITION_WITH_RULE_ALTCHARS)