aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/charset.c33
2 files changed, 28 insertions, 11 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index f1f4aa24b35..4837d8ecb06 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
12010-02-06 Chong Yidong <cyd@stupidchicken.com>
2
3 * charset.c (load_charset_map_from_file)
4 (load_charset_map_from_vector): Fix last change to use SAFE_ALLOCA
5 instead of xmalloc (Bug#5526). Suggested by Vivek Dasmohapatra.
6
12010-02-05 Chong Yidong <cyd@stupidchicken.com> 72010-02-05 Chong Yidong <cyd@stupidchicken.com>
2 8
3 * charset.c (load_charset_map_from_file): Allocate large 9 * charset.c (load_charset_map_from_file): Allocate large
diff --git a/src/charset.c b/src/charset.c
index 9e8ff1d59c9..1db9ec17ae7 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -512,12 +512,13 @@ load_charset_map_from_file (charset, mapfile, control_flag)
512 int eof; 512 int eof;
513 Lisp_Object suffixes; 513 Lisp_Object suffixes;
514 struct charset_map_entries *head, *entries; 514 struct charset_map_entries *head, *entries;
515 int n_entries; 515 int n_entries, count;
516 int count = SPECPDL_INDEX (); 516 USE_SAFE_ALLOCA;
517 517
518 suffixes = Fcons (build_string (".map"), 518 suffixes = Fcons (build_string (".map"),
519 Fcons (build_string (".TXT"), Qnil)); 519 Fcons (build_string (".TXT"), Qnil));
520 520
521 count = SPECPDL_INDEX ();
521 specbind (Qfile_name_handler_alist, Qnil); 522 specbind (Qfile_name_handler_alist, Qnil);
522 fd = openp (Vcharset_map_path, mapfile, suffixes, NULL, Qnil); 523 fd = openp (Vcharset_map_path, mapfile, suffixes, NULL, Qnil);
523 unbind_to (count, Qnil); 524 unbind_to (count, Qnil);
@@ -525,8 +526,12 @@ load_charset_map_from_file (charset, mapfile, control_flag)
525 || ! (fp = fdopen (fd, "r"))) 526 || ! (fp = fdopen (fd, "r")))
526 error ("Failure in loading charset map: %S", SDATA (mapfile)); 527 error ("Failure in loading charset map: %S", SDATA (mapfile));
527 528
528 head = entries = ((struct charset_map_entries *) 529 /* Use SAFE_ALLOCA instead of alloca, as `charset_map_entries' is
529 xmalloc (sizeof (struct charset_map_entries))); 530 large (larger than MAX_ALLOCA). */
531 SAFE_ALLOCA (head, struct charset_map_entries *,
532 sizeof (struct charset_map_entries));
533 entries = head;
534
530 n_entries = 0; 535 n_entries = 0;
531 eof = 0; 536 eof = 0;
532 while (1) 537 while (1)
@@ -549,8 +554,8 @@ load_charset_map_from_file (charset, mapfile, control_flag)
549 554
550 if (n_entries > 0 && (n_entries % 0x10000) == 0) 555 if (n_entries > 0 && (n_entries % 0x10000) == 0)
551 { 556 {
552 entries->next = ((struct charset_map_entries *) 557 SAFE_ALLOCA (entries->next, struct charset_map_entries *,
553 alloca (sizeof (struct charset_map_entries))); 558 sizeof (struct charset_map_entries));
554 entries = entries->next; 559 entries = entries->next;
555 } 560 }
556 idx = n_entries % 0x10000; 561 idx = n_entries % 0x10000;
@@ -563,7 +568,7 @@ load_charset_map_from_file (charset, mapfile, control_flag)
563 close (fd); 568 close (fd);
564 569
565 load_charset_map (charset, head, n_entries, control_flag); 570 load_charset_map (charset, head, n_entries, control_flag);
566 xfree (head); 571 SAFE_FREE ();
567} 572}
568 573
569static void 574static void
@@ -578,6 +583,7 @@ load_charset_map_from_vector (charset, vec, control_flag)
578 int n_entries; 583 int n_entries;
579 int len = ASIZE (vec); 584 int len = ASIZE (vec);
580 int i; 585 int i;
586 USE_SAFE_ALLOCA;
581 587
582 if (len % 2 == 1) 588 if (len % 2 == 1)
583 { 589 {
@@ -585,8 +591,12 @@ load_charset_map_from_vector (charset, vec, control_flag)
585 return; 591 return;
586 } 592 }
587 593
588 head = entries = ((struct charset_map_entries *) 594 /* Use SAFE_ALLOCA instead of alloca, as `charset_map_entries' is
589 alloca (sizeof (struct charset_map_entries))); 595 large (larger than MAX_ALLOCA). */
596 SAFE_ALLOCA (head, struct charset_map_entries *,
597 sizeof (struct charset_map_entries));
598 entries = head;
599
590 n_entries = 0; 600 n_entries = 0;
591 for (i = 0; i < len; i += 2) 601 for (i = 0; i < len; i += 2)
592 { 602 {
@@ -619,8 +629,8 @@ load_charset_map_from_vector (charset, vec, control_flag)
619 629
620 if (n_entries > 0 && (n_entries % 0x10000) == 0) 630 if (n_entries > 0 && (n_entries % 0x10000) == 0)
621 { 631 {
622 entries->next = ((struct charset_map_entries *) 632 SAFE_ALLOCA (entries->next, struct charset_map_entries *,
623 alloca (sizeof (struct charset_map_entries))); 633 sizeof (struct charset_map_entries));
624 entries = entries->next; 634 entries = entries->next;
625 } 635 }
626 idx = n_entries % 0x10000; 636 idx = n_entries % 0x10000;
@@ -631,6 +641,7 @@ load_charset_map_from_vector (charset, vec, control_flag)
631 } 641 }
632 642
633 load_charset_map (charset, head, n_entries, control_flag); 643 load_charset_map (charset, head, n_entries, control_flag);
644 SAFE_FREE ();
634} 645}
635 646
636 647