Commit a2f3eb19 authored by Chong Yidong's avatar Chong Yidong
Browse files

* charset.c (load_charset_map_from_file)

(load_charset_map_from_vector): Fix last change to use SAFE_ALLOCA
instead of xmalloc (Bug#5526).
parent ffe87109
2010-02-06 Chong Yidong <cyd@stupidchicken.com>
* charset.c (load_charset_map_from_file)
(load_charset_map_from_vector): Fix last change to use SAFE_ALLOCA
instead of xmalloc (Bug#5526).
2010-02-05 Chong Yidong <cyd@stupidchicken.com> 2010-02-05 Chong Yidong <cyd@stupidchicken.com>
   
* charset.c (load_charset_map_from_file): Allocate large * charset.c (load_charset_map_from_file): Allocate large
......
...@@ -512,12 +512,13 @@ load_charset_map_from_file (charset, mapfile, control_flag) ...@@ -512,12 +512,13 @@ load_charset_map_from_file (charset, mapfile, control_flag)
int eof; int eof;
Lisp_Object suffixes; Lisp_Object suffixes;
struct charset_map_entries *head, *entries; struct charset_map_entries *head, *entries;
int n_entries; int n_entries, count;
int count = SPECPDL_INDEX (); USE_SAFE_ALLOCA;
suffixes = Fcons (build_string (".map"), suffixes = Fcons (build_string (".map"),
Fcons (build_string (".TXT"), Qnil)); Fcons (build_string (".TXT"), Qnil));
count = SPECPDL_INDEX ();
specbind (Qfile_name_handler_alist, Qnil); specbind (Qfile_name_handler_alist, Qnil);
fd = openp (Vcharset_map_path, mapfile, suffixes, NULL, Qnil); fd = openp (Vcharset_map_path, mapfile, suffixes, NULL, Qnil);
unbind_to (count, Qnil); unbind_to (count, Qnil);
...@@ -525,8 +526,12 @@ load_charset_map_from_file (charset, mapfile, control_flag) ...@@ -525,8 +526,12 @@ load_charset_map_from_file (charset, mapfile, control_flag)
|| ! (fp = fdopen (fd, "r"))) || ! (fp = fdopen (fd, "r")))
error ("Failure in loading charset map: %S", SDATA (mapfile)); error ("Failure in loading charset map: %S", SDATA (mapfile));
head = entries = ((struct charset_map_entries *) /* Use SAFE_ALLOCA instead of alloca, as `charset_map_entries' is
xmalloc (sizeof (struct charset_map_entries))); large (larger than MAX_ALLOCA). */
SAFE_ALLOCA (head, struct charset_map_entries *,
sizeof (struct charset_map_entries));
entries = head;
n_entries = 0; n_entries = 0;
eof = 0; eof = 0;
while (1) while (1)
...@@ -549,8 +554,8 @@ load_charset_map_from_file (charset, mapfile, control_flag) ...@@ -549,8 +554,8 @@ load_charset_map_from_file (charset, mapfile, control_flag)
if (n_entries > 0 && (n_entries % 0x10000) == 0) if (n_entries > 0 && (n_entries % 0x10000) == 0)
{ {
entries->next = ((struct charset_map_entries *) SAFE_ALLOCA (entries->next, struct charset_map_entries *,
alloca (sizeof (struct charset_map_entries))); sizeof (struct charset_map_entries));
entries = entries->next; entries = entries->next;
} }
idx = n_entries % 0x10000; idx = n_entries % 0x10000;
...@@ -563,7 +568,7 @@ load_charset_map_from_file (charset, mapfile, control_flag) ...@@ -563,7 +568,7 @@ load_charset_map_from_file (charset, mapfile, control_flag)
close (fd); close (fd);
load_charset_map (charset, head, n_entries, control_flag); load_charset_map (charset, head, n_entries, control_flag);
xfree (head); SAFE_FREE ();
} }
static void static void
...@@ -578,6 +583,7 @@ load_charset_map_from_vector (charset, vec, control_flag) ...@@ -578,6 +583,7 @@ load_charset_map_from_vector (charset, vec, control_flag)
int n_entries; int n_entries;
int len = ASIZE (vec); int len = ASIZE (vec);
int i; int i;
USE_SAFE_ALLOCA;
if (len % 2 == 1) if (len % 2 == 1)
{ {
...@@ -585,8 +591,12 @@ load_charset_map_from_vector (charset, vec, control_flag) ...@@ -585,8 +591,12 @@ load_charset_map_from_vector (charset, vec, control_flag)
return; return;
} }
head = entries = ((struct charset_map_entries *) /* Use SAFE_ALLOCA instead of alloca, as `charset_map_entries' is
alloca (sizeof (struct charset_map_entries))); large (larger than MAX_ALLOCA). */
SAFE_ALLOCA (head, struct charset_map_entries *,
sizeof (struct charset_map_entries));
entries = head;
n_entries = 0; n_entries = 0;
for (i = 0; i < len; i += 2) for (i = 0; i < len; i += 2)
{ {
...@@ -619,8 +629,8 @@ load_charset_map_from_vector (charset, vec, control_flag) ...@@ -619,8 +629,8 @@ load_charset_map_from_vector (charset, vec, control_flag)
if (n_entries > 0 && (n_entries % 0x10000) == 0) if (n_entries > 0 && (n_entries % 0x10000) == 0)
{ {
entries->next = ((struct charset_map_entries *) SAFE_ALLOCA (entries->next, struct charset_map_entries *,
alloca (sizeof (struct charset_map_entries))); sizeof (struct charset_map_entries));
entries = entries->next; entries = entries->next;
} }
idx = n_entries % 0x10000; idx = n_entries % 0x10000;
...@@ -631,6 +641,7 @@ load_charset_map_from_vector (charset, vec, control_flag) ...@@ -631,6 +641,7 @@ load_charset_map_from_vector (charset, vec, control_flag)
} }
load_charset_map (charset, head, n_entries, control_flag); load_charset_map (charset, head, n_entries, control_flag);
SAFE_FREE ();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment