aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-07-18 20:34:13 -0700
committerPaul Eggert2011-07-18 20:34:13 -0700
commite097a6fa863b26952a476e71a786fa7b2460277b (patch)
tree759c9146fe747732a9243b6070ed0a31317dc713 /src
parent5637687fead7d57f73ea9a7677d25b93fb785dc7 (diff)
downloademacs-e097a6fa863b26952a476e71a786fa7b2460277b.tar.gz
emacs-e097a6fa863b26952a476e71a786fa7b2460277b.zip
* charset.c (Fdefine_charset_internal): Check for integer overflow.
Add a FIXME comment about memory leaks. (syms_of_charset): Don't assume xmalloc returns.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog4
-rw-r--r--src/charset.c20
2 files changed, 21 insertions, 3 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 54ce0c8df4e..4a9e03d5da0 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,9 @@
12011-07-19 Paul Eggert <eggert@cs.ucla.edu> 12011-07-19 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 * charset.c (Fdefine_charset_internal): Check for integer overflow.
4 Add a FIXME comment about memory leaks.
5 (syms_of_charset): Don't assume xmalloc returns.
6
3 Don't assume that stated character widths fit in int. 7 Don't assume that stated character widths fit in int.
4 * character.c (Fchar_width, c_string_width, lisp_string_width): 8 * character.c (Fchar_width, c_string_width, lisp_string_width):
5 * character.h (CHAR_WIDTH): 9 * character.h (CHAR_WIDTH):
diff --git a/src/charset.c b/src/charset.c
index e2bfcd08671..852aeb19bcb 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -1150,13 +1150,28 @@ usage: (define-charset-internal ...) */)
1150 hash_code); 1150 hash_code);
1151 if (charset_table_used == charset_table_size) 1151 if (charset_table_used == charset_table_size)
1152 { 1152 {
1153 struct charset *new_table 1153 struct charset *new_table;
1154 /* Ensure that charset IDs fit into 'int' as well as into the
1155 restriction imposed by fixnums, ptrdiff_t, and size_t.
1156 Although the 'int' restriction could be removed, too much other
1157 code would need altering; for example, the IDs are stuffed into
1158 struct coding_system.charbuf[i] entries, which are 'int'. */
1159 int charset_table_size_max =
1160 min (min (INT_MAX, MOST_POSITIVE_FIXNUM),
1161 min (PTRDIFF_MAX, SIZE_MAX) / sizeof (struct charset));
1162 if (charset_table_size_max - 16 < charset_table_size)
1163 memory_full (SIZE_MAX);
1164 new_table
1154 = (struct charset *) xmalloc (sizeof (struct charset) 1165 = (struct charset *) xmalloc (sizeof (struct charset)
1155 * (charset_table_size + 16)); 1166 * (charset_table_size + 16));
1156 memcpy (new_table, charset_table, 1167 memcpy (new_table, charset_table,
1157 sizeof (struct charset) * charset_table_size); 1168 sizeof (struct charset) * charset_table_size);
1158 charset_table_size += 16; 1169 charset_table_size += 16;
1159 charset_table = new_table; 1170 charset_table = new_table;
1171 /* FIXME: Doesn't this leak memory? The old charset_table
1172 becomes unreachable. If the memory leak is intentional,
1173 a comment should be added to explain this. If not, the
1174 old charset_table should be freed, using xfree. */
1160 } 1175 }
1161 id = charset_table_used++; 1176 id = charset_table_used++;
1162 new_definition_p = 1; 1177 new_definition_p = 1;
@@ -2347,9 +2362,8 @@ syms_of_charset (void)
2347 Vcharset_hash_table = Fmake_hash_table (2, args); 2362 Vcharset_hash_table = Fmake_hash_table (2, args);
2348 } 2363 }
2349 2364
2365 charset_table = (struct charset *) xmalloc (sizeof (struct charset) * 128);
2350 charset_table_size = 128; 2366 charset_table_size = 128;
2351 charset_table = ((struct charset *)
2352 xmalloc (sizeof (struct charset) * charset_table_size));
2353 charset_table_used = 0; 2367 charset_table_used = 0;
2354 2368
2355 defsubr (&Scharsetp); 2369 defsubr (&Scharsetp);