aboutsummaryrefslogtreecommitdiffstats
path: root/src/term.c
diff options
context:
space:
mode:
authorJoakim Verona2011-08-27 19:45:48 +0200
committerJoakim Verona2011-08-27 19:45:48 +0200
commit9fb7b0cab34a48a4c7b66abb6b8edc4ee20467b4 (patch)
treee94476d49f15747fcb9409d773702e88201855a4 /src/term.c
parentc7489583c30031c0ecfae9d20b20c149ca1935e9 (diff)
parentb75258b32810f3690442bddef2e10eef126d2d25 (diff)
downloademacs-9fb7b0cab34a48a4c7b66abb6b8edc4ee20467b4.tar.gz
emacs-9fb7b0cab34a48a4c7b66abb6b8edc4ee20467b4.zip
upstream
Diffstat (limited to 'src/term.c')
-rw-r--r--src/term.c79
1 files changed, 36 insertions, 43 deletions
diff --git a/src/term.c b/src/term.c
index 22056451cb9..f3bf3a947cb 100644
--- a/src/term.c
+++ b/src/term.c
@@ -136,10 +136,6 @@ enum no_color_bit
136 136
137static int max_frame_cols; 137static int max_frame_cols;
138 138
139/* The largest frame height in any call to calculate_costs. */
140
141static int max_frame_lines;
142
143/* Non-zero if we have dropped our controlling tty and therefore 139/* Non-zero if we have dropped our controlling tty and therefore
144 should not open a frame on stdout. */ 140 should not open a frame on stdout. */
145static int no_controlling_tty; 141static int no_controlling_tty;
@@ -497,8 +493,8 @@ tty_clear_end_of_line (struct frame *f, int first_unused_hpos)
497static unsigned char *encode_terminal_src; 493static unsigned char *encode_terminal_src;
498static unsigned char *encode_terminal_dst; 494static unsigned char *encode_terminal_dst;
499/* Allocated sizes of the above buffers. */ 495/* Allocated sizes of the above buffers. */
500static int encode_terminal_src_size; 496static ptrdiff_t encode_terminal_src_size;
501static int encode_terminal_dst_size; 497static ptrdiff_t encode_terminal_dst_size;
502 498
503/* Encode SRC_LEN glyphs starting at SRC to terminal output codes. 499/* Encode SRC_LEN glyphs starting at SRC to terminal output codes.
504 Set CODING->produced to the byte-length of the resulting byte 500 Set CODING->produced to the byte-length of the resulting byte
@@ -509,8 +505,8 @@ encode_terminal_code (struct glyph *src, int src_len, struct coding_system *codi
509{ 505{
510 struct glyph *src_end = src + src_len; 506 struct glyph *src_end = src + src_len;
511 unsigned char *buf; 507 unsigned char *buf;
512 int nchars, nbytes, required; 508 ptrdiff_t nchars, nbytes, required;
513 register int tlen = GLYPH_TABLE_LENGTH; 509 ptrdiff_t tlen = GLYPH_TABLE_LENGTH;
514 register Lisp_Object *tbase = GLYPH_TABLE_BASE; 510 register Lisp_Object *tbase = GLYPH_TABLE_BASE;
515 Lisp_Object charset_list; 511 Lisp_Object charset_list;
516 512
@@ -518,13 +514,13 @@ encode_terminal_code (struct glyph *src, int src_len, struct coding_system *codi
518 multibyte-form. But, it may be enlarged on demand if 514 multibyte-form. But, it may be enlarged on demand if
519 Vglyph_table contains a string or a composite glyph is 515 Vglyph_table contains a string or a composite glyph is
520 encountered. */ 516 encountered. */
521 required = MAX_MULTIBYTE_LENGTH * src_len; 517 if (min (PTRDIFF_MAX, SIZE_MAX) / MAX_MULTIBYTE_LENGTH < src_len)
518 memory_full (SIZE_MAX);
519 required = src_len;
520 required *= MAX_MULTIBYTE_LENGTH;
522 if (encode_terminal_src_size < required) 521 if (encode_terminal_src_size < required)
523 { 522 {
524 if (encode_terminal_src) 523 encode_terminal_src = xrealloc (encode_terminal_src, required);
525 encode_terminal_src = xrealloc (encode_terminal_src, required);
526 else
527 encode_terminal_src = xmalloc (required);
528 encode_terminal_src_size = required; 524 encode_terminal_src_size = required;
529 } 525 }
530 526
@@ -544,19 +540,21 @@ encode_terminal_code (struct glyph *src, int src_len, struct coding_system *codi
544 if (src->u.cmp.automatic) 540 if (src->u.cmp.automatic)
545 { 541 {
546 gstring = composition_gstring_from_id (src->u.cmp.id); 542 gstring = composition_gstring_from_id (src->u.cmp.id);
547 required = src->slice.cmp.to + 1 - src->slice.cmp.from; 543 required = src->slice.cmp.to - src->slice.cmp.from + 1;
548 } 544 }
549 else 545 else
550 { 546 {
551 cmp = composition_table[src->u.cmp.id]; 547 cmp = composition_table[src->u.cmp.id];
552 required = MAX_MULTIBYTE_LENGTH * cmp->glyph_len; 548 required = cmp->glyph_len;
549 required *= MAX_MULTIBYTE_LENGTH;
553 } 550 }
554 551
555 if (encode_terminal_src_size < nbytes + required) 552 if (encode_terminal_src_size - nbytes < required)
556 { 553 {
557 encode_terminal_src_size = nbytes + required; 554 encode_terminal_src =
558 encode_terminal_src = xrealloc (encode_terminal_src, 555 xpalloc (encode_terminal_src, &encode_terminal_src_size,
559 encode_terminal_src_size); 556 required - (encode_terminal_src_size - nbytes),
557 -1, 1);
560 buf = encode_terminal_src + nbytes; 558 buf = encode_terminal_src + nbytes;
561 } 559 }
562 560
@@ -627,11 +625,11 @@ encode_terminal_code (struct glyph *src, int src_len, struct coding_system *codi
627 if (NILP (string)) 625 if (NILP (string))
628 { 626 {
629 nbytes = buf - encode_terminal_src; 627 nbytes = buf - encode_terminal_src;
630 if (encode_terminal_src_size < nbytes + MAX_MULTIBYTE_LENGTH) 628 if (encode_terminal_src_size - nbytes < MAX_MULTIBYTE_LENGTH)
631 { 629 {
632 encode_terminal_src_size = nbytes + MAX_MULTIBYTE_LENGTH; 630 encode_terminal_src =
633 encode_terminal_src = xrealloc (encode_terminal_src, 631 xpalloc (encode_terminal_src, &encode_terminal_src_size,
634 encode_terminal_src_size); 632 MAX_MULTIBYTE_LENGTH, -1, 1);
635 buf = encode_terminal_src + nbytes; 633 buf = encode_terminal_src + nbytes;
636 } 634 }
637 if (CHAR_BYTE8_P (c) 635 if (CHAR_BYTE8_P (c)
@@ -659,11 +657,13 @@ encode_terminal_code (struct glyph *src, int src_len, struct coding_system *codi
659 if (! STRING_MULTIBYTE (string)) 657 if (! STRING_MULTIBYTE (string))
660 string = string_to_multibyte (string); 658 string = string_to_multibyte (string);
661 nbytes = buf - encode_terminal_src; 659 nbytes = buf - encode_terminal_src;
662 if (encode_terminal_src_size < nbytes + SBYTES (string)) 660 if (encode_terminal_src_size - nbytes < SBYTES (string))
663 { 661 {
664 encode_terminal_src_size = nbytes + SBYTES (string); 662 encode_terminal_src =
665 encode_terminal_src = xrealloc (encode_terminal_src, 663 xpalloc (encode_terminal_src, &encode_terminal_src_size,
666 encode_terminal_src_size); 664 (SBYTES (string)
665 - (encode_terminal_src_size - nbytes)),
666 -1, 1);
667 buf = encode_terminal_src + nbytes; 667 buf = encode_terminal_src + nbytes;
668 } 668 }
669 memcpy (buf, SDATA (string), SBYTES (string)); 669 memcpy (buf, SDATA (string), SBYTES (string));
@@ -684,12 +684,9 @@ encode_terminal_code (struct glyph *src, int src_len, struct coding_system *codi
684 coding->source = encode_terminal_src; 684 coding->source = encode_terminal_src;
685 if (encode_terminal_dst_size == 0) 685 if (encode_terminal_dst_size == 0)
686 { 686 {
687 encode_terminal_dst = xrealloc (encode_terminal_dst,
688 encode_terminal_src_size);
687 encode_terminal_dst_size = encode_terminal_src_size; 689 encode_terminal_dst_size = encode_terminal_src_size;
688 if (encode_terminal_dst)
689 encode_terminal_dst = xrealloc (encode_terminal_dst,
690 encode_terminal_dst_size);
691 else
692 encode_terminal_dst = xmalloc (encode_terminal_dst_size);
693 } 690 }
694 coding->destination = encode_terminal_dst; 691 coding->destination = encode_terminal_dst;
695 coding->dst_bytes = encode_terminal_dst_size; 692 coding->dst_bytes = encode_terminal_dst_size;
@@ -1156,21 +1153,17 @@ calculate_costs (struct frame *frame)
1156 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because 1153 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because
1157 X turns off char_ins_del_ok. */ 1154 X turns off char_ins_del_ok. */
1158 1155
1159 max_frame_lines = max (max_frame_lines, FRAME_LINES (frame));
1160 max_frame_cols = max (max_frame_cols, FRAME_COLS (frame)); 1156 max_frame_cols = max (max_frame_cols, FRAME_COLS (frame));
1157 if ((min (PTRDIFF_MAX, SIZE_MAX) / sizeof (int) - 1) / 2
1158 < max_frame_cols)
1159 memory_full (SIZE_MAX);
1161 1160
1162 if (char_ins_del_vector != 0) 1161 char_ins_del_vector =
1163 char_ins_del_vector 1162 xrealloc (char_ins_del_vector,
1164 = (int *) xrealloc (char_ins_del_vector, 1163 (sizeof (int) + 2 * sizeof (int) * max_frame_cols));
1165 (sizeof (int)
1166 + 2 * max_frame_cols * sizeof (int)));
1167 else
1168 char_ins_del_vector
1169 = (int *) xmalloc (sizeof (int)
1170 + 2 * max_frame_cols * sizeof (int));
1171 1164
1172 memset (char_ins_del_vector, 0, 1165 memset (char_ins_del_vector, 0,
1173 (sizeof (int) + 2 * max_frame_cols * sizeof (int))); 1166 (sizeof (int) + 2 * sizeof (int) * max_frame_cols));
1174 1167
1175 1168
1176 if (f && (!tty->TS_ins_line && !tty->TS_del_line)) 1169 if (f && (!tty->TS_ins_line && !tty->TS_del_line))