aboutsummaryrefslogtreecommitdiffstats
path: root/src/regex.c
diff options
context:
space:
mode:
authorPaul Eggert2012-07-05 11:35:48 -0700
committerPaul Eggert2012-07-05 11:35:48 -0700
commit38182d901d030c7d65f4aa7a49b583afb30eb9b7 (patch)
treea69e1a571495d6ca1c034359d7c995639774ab9b /src/regex.c
parent6dd5a677dbf794eedaa8325c46d57ac041373361 (diff)
downloademacs-38182d901d030c7d65f4aa7a49b583afb30eb9b7.tar.gz
emacs-38182d901d030c7d65f4aa7a49b583afb30eb9b7.zip
More xmalloc and related cleanup.
* alloc.c, bidi.c, buffer.c, buffer.h, bytecode.c, callint.c: * callproc.c, charset.c, coding.c, composite.c, data.c, dispnew.c: * doc.c, editfns.c, emacs.c, eval.c, fileio.c, filelock.c, fns.c: * font.c, fontset.c, frame.c, fringe.c, ftfont.c, ftxfont.c, gmalloc.c: * gtkutil.c, image.c, keyboard.c, keymap.c, lread.c, macros.c, menu.c: * nsfns.m, nsfont.m, nsmenu.m, nsterm.m, print.c, process.c, ralloc.c: * regex.c, region-cache.c, scroll.c, search.c, sound.c, syntax.c: * sysdep.c, term.c, termcap.c, unexmacosx.c, window.c, xdisp.c: * xfaces.c, xfns.c, xftfont.c, xgselect.c, xmenu.c, xrdb.c, xselect.c: * xterm.c: Omit needless casts involving void * pointers and allocation. Prefer "P = xmalloc (sizeof *P)" to "P = xmalloc (sizeof (TYPE_OF_P))", as the former is more robust if P's type is changed. Prefer xzalloc to xmalloc + memset 0. Simplify malloc-or-realloc to realloc. Don't worry about xmalloc returning a null pointer. Prefer xstrdup to xmalloc + strcpy. * editfns.c (Fmessage_box): Grow message_text by at least 80 when growing it. * keyboard.c (apply_modifiers_uncached): Prefer local array to alloca of a constant.
Diffstat (limited to 'src/regex.c')
-rw-r--r--src/regex.c43
1 files changed, 13 insertions, 30 deletions
diff --git a/src/regex.c b/src/regex.c
index f3f70060b2e..751006d57ba 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -212,8 +212,7 @@
212static void * 212static void *
213xmalloc (size_t size) 213xmalloc (size_t size)
214{ 214{
215 register void *val; 215 void *val = malloc (size);
216 val = (void *) malloc (size);
217 if (!val && size) 216 if (!val && size)
218 { 217 {
219 write (2, "virtual memory exhausted\n", 25); 218 write (2, "virtual memory exhausted\n", 25);
@@ -225,13 +224,13 @@ xmalloc (size_t size)
225static void * 224static void *
226xrealloc (void *block, size_t size) 225xrealloc (void *block, size_t size)
227{ 226{
228 register void *val; 227 void *val;
229 /* We must call malloc explicitly when BLOCK is 0, since some 228 /* We must call malloc explicitly when BLOCK is 0, since some
230 reallocs don't do this. */ 229 reallocs don't do this. */
231 if (! block) 230 if (! block)
232 val = (void *) malloc (size); 231 val = malloc (size);
233 else 232 else
234 val = (void *) realloc (block, size); 233 val = realloc (block, size);
235 if (!val && size) 234 if (!val && size)
236 { 235 {
237 write (2, "virtual memory exhausted\n", 25); 236 write (2, "virtual memory exhausted\n", 25);
@@ -1386,7 +1385,7 @@ typedef struct
1386#ifdef MATCH_MAY_ALLOCATE 1385#ifdef MATCH_MAY_ALLOCATE
1387# define INIT_FAIL_STACK() \ 1386# define INIT_FAIL_STACK() \
1388 do { \ 1387 do { \
1389 fail_stack.stack = (fail_stack_elt_t *) \ 1388 fail_stack.stack = \
1390 REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * TYPICAL_FAILURE_SIZE \ 1389 REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * TYPICAL_FAILURE_SIZE \
1391 * sizeof (fail_stack_elt_t)); \ 1390 * sizeof (fail_stack_elt_t)); \
1392 \ 1391 \
@@ -1429,8 +1428,7 @@ typedef struct
1429 >= re_max_failures * TYPICAL_FAILURE_SIZE) \ 1428 >= re_max_failures * TYPICAL_FAILURE_SIZE) \
1430 ? 0 \ 1429 ? 0 \
1431 : ((fail_stack).stack \ 1430 : ((fail_stack).stack \
1432 = (fail_stack_elt_t *) \ 1431 = REGEX_REALLOCATE_STACK ((fail_stack).stack, \
1433 REGEX_REALLOCATE_STACK ((fail_stack).stack, \
1434 (fail_stack).size * sizeof (fail_stack_elt_t), \ 1432 (fail_stack).size * sizeof (fail_stack_elt_t), \
1435 MIN (re_max_failures * TYPICAL_FAILURE_SIZE, \ 1433 MIN (re_max_failures * TYPICAL_FAILURE_SIZE, \
1436 ((fail_stack).size * sizeof (fail_stack_elt_t) \ 1434 ((fail_stack).size * sizeof (fail_stack_elt_t) \
@@ -2141,12 +2139,7 @@ static void
2141extend_range_table_work_area (struct range_table_work_area *work_area) 2139extend_range_table_work_area (struct range_table_work_area *work_area)
2142{ 2140{
2143 work_area->allocated += 16 * sizeof (int); 2141 work_area->allocated += 16 * sizeof (int);
2144 if (work_area->table) 2142 work_area->table = realloc (work_area->table, work_area->allocated);
2145 work_area->table
2146 = (int *) realloc (work_area->table, work_area->allocated);
2147 else
2148 work_area->table
2149 = (int *) malloc (work_area->allocated);
2150} 2143}
2151 2144
2152#if 0 2145#if 0
@@ -3741,16 +3734,8 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct
3741 if (fail_stack.size < re_max_failures * TYPICAL_FAILURE_SIZE) 3734 if (fail_stack.size < re_max_failures * TYPICAL_FAILURE_SIZE)
3742 { 3735 {
3743 fail_stack.size = re_max_failures * TYPICAL_FAILURE_SIZE; 3736 fail_stack.size = re_max_failures * TYPICAL_FAILURE_SIZE;
3744 3737 falk_stack.stack = realloc (fail_stack.stack,
3745 if (! fail_stack.stack) 3738 fail_stack.size * sizeof *falk_stack.stack);
3746 fail_stack.stack
3747 = (fail_stack_elt_t *) malloc (fail_stack.size
3748 * sizeof (fail_stack_elt_t));
3749 else
3750 fail_stack.stack
3751 = (fail_stack_elt_t *) realloc (fail_stack.stack,
3752 (fail_stack.size
3753 * sizeof (fail_stack_elt_t)));
3754 } 3739 }
3755 3740
3756 regex_grow_registers (num_regs); 3741 regex_grow_registers (num_regs);
@@ -6408,13 +6393,13 @@ re_comp (const char *s)
6408 6393
6409 if (!re_comp_buf.buffer) 6394 if (!re_comp_buf.buffer)
6410 { 6395 {
6411 re_comp_buf.buffer = (unsigned char *) malloc (200); 6396 re_comp_buf.buffer = malloc (200);
6412 if (re_comp_buf.buffer == NULL) 6397 if (re_comp_buf.buffer == NULL)
6413 /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */ 6398 /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */
6414 return (char *) gettext (re_error_msgid[(int) REG_ESPACE]); 6399 return (char *) gettext (re_error_msgid[(int) REG_ESPACE]);
6415 re_comp_buf.allocated = 200; 6400 re_comp_buf.allocated = 200;
6416 6401
6417 re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH); 6402 re_comp_buf.fastmap = malloc (1 << BYTEWIDTH);
6418 if (re_comp_buf.fastmap == NULL) 6403 if (re_comp_buf.fastmap == NULL)
6419 /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */ 6404 /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */
6420 return (char *) gettext (re_error_msgid[(int) REG_ESPACE]); 6405 return (char *) gettext (re_error_msgid[(int) REG_ESPACE]);
@@ -6498,15 +6483,13 @@ regcomp (regex_t *__restrict preg, const char *__restrict pattern,
6498 preg->used = 0; 6483 preg->used = 0;
6499 6484
6500 /* Try to allocate space for the fastmap. */ 6485 /* Try to allocate space for the fastmap. */
6501 preg->fastmap = (char *) malloc (1 << BYTEWIDTH); 6486 preg->fastmap = malloc (1 << BYTEWIDTH);
6502 6487
6503 if (cflags & REG_ICASE) 6488 if (cflags & REG_ICASE)
6504 { 6489 {
6505 unsigned i; 6490 unsigned i;
6506 6491
6507 preg->translate 6492 preg->translate = malloc (CHAR_SET_SIZE * sizeof *preg->translate);
6508 = (RE_TRANSLATE_TYPE) malloc (CHAR_SET_SIZE
6509 * sizeof (*(RE_TRANSLATE_TYPE)0));
6510 if (preg->translate == NULL) 6493 if (preg->translate == NULL)
6511 return (int) REG_ESPACE; 6494 return (int) REG_ESPACE;
6512 6495