summaryrefslogtreecommitdiff
path: root/src/regex.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2012-07-05 11:35:48 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2012-07-05 11:35:48 -0700
commit38182d901d030c7d65f4aa7a49b583afb30eb9b7 (patch)
treea69e1a571495d6ca1c034359d7c995639774ab9b /src/regex.c
parent6dd5a677dbf794eedaa8325c46d57ac041373361 (diff)
downloademacs-38182d901d030c7d65f4aa7a49b583afb30eb9b7.tar.gz
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 @@
static void *
xmalloc (size_t size)
{
- register void *val;
- val = (void *) malloc (size);
+ void *val = malloc (size);
if (!val && size)
{
write (2, "virtual memory exhausted\n", 25);
@@ -225,13 +224,13 @@ xmalloc (size_t size)
static void *
xrealloc (void *block, size_t size)
{
- register void *val;
+ void *val;
/* We must call malloc explicitly when BLOCK is 0, since some
reallocs don't do this. */
if (! block)
- val = (void *) malloc (size);
+ val = malloc (size);
else
- val = (void *) realloc (block, size);
+ val = realloc (block, size);
if (!val && size)
{
write (2, "virtual memory exhausted\n", 25);
@@ -1386,7 +1385,7 @@ typedef struct
#ifdef MATCH_MAY_ALLOCATE
# define INIT_FAIL_STACK() \
do { \
- fail_stack.stack = (fail_stack_elt_t *) \
+ fail_stack.stack = \
REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * TYPICAL_FAILURE_SIZE \
* sizeof (fail_stack_elt_t)); \
\
@@ -1429,8 +1428,7 @@ typedef struct
>= re_max_failures * TYPICAL_FAILURE_SIZE) \
? 0 \
: ((fail_stack).stack \
- = (fail_stack_elt_t *) \
- REGEX_REALLOCATE_STACK ((fail_stack).stack, \
+ = REGEX_REALLOCATE_STACK ((fail_stack).stack, \
(fail_stack).size * sizeof (fail_stack_elt_t), \
MIN (re_max_failures * TYPICAL_FAILURE_SIZE, \
((fail_stack).size * sizeof (fail_stack_elt_t) \
@@ -2141,12 +2139,7 @@ static void
extend_range_table_work_area (struct range_table_work_area *work_area)
{
work_area->allocated += 16 * sizeof (int);
- if (work_area->table)
- work_area->table
- = (int *) realloc (work_area->table, work_area->allocated);
- else
- work_area->table
- = (int *) malloc (work_area->allocated);
+ work_area->table = realloc (work_area->table, work_area->allocated);
}
#if 0
@@ -3741,16 +3734,8 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct
if (fail_stack.size < re_max_failures * TYPICAL_FAILURE_SIZE)
{
fail_stack.size = re_max_failures * TYPICAL_FAILURE_SIZE;
-
- if (! fail_stack.stack)
- fail_stack.stack
- = (fail_stack_elt_t *) malloc (fail_stack.size
- * sizeof (fail_stack_elt_t));
- else
- fail_stack.stack
- = (fail_stack_elt_t *) realloc (fail_stack.stack,
- (fail_stack.size
- * sizeof (fail_stack_elt_t)));
+ falk_stack.stack = realloc (fail_stack.stack,
+ fail_stack.size * sizeof *falk_stack.stack);
}
regex_grow_registers (num_regs);
@@ -6408,13 +6393,13 @@ re_comp (const char *s)
if (!re_comp_buf.buffer)
{
- re_comp_buf.buffer = (unsigned char *) malloc (200);
+ re_comp_buf.buffer = malloc (200);
if (re_comp_buf.buffer == NULL)
/* Yes, we're discarding `const' here if !HAVE_LIBINTL. */
return (char *) gettext (re_error_msgid[(int) REG_ESPACE]);
re_comp_buf.allocated = 200;
- re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH);
+ re_comp_buf.fastmap = malloc (1 << BYTEWIDTH);
if (re_comp_buf.fastmap == NULL)
/* Yes, we're discarding `const' here if !HAVE_LIBINTL. */
return (char *) gettext (re_error_msgid[(int) REG_ESPACE]);
@@ -6498,15 +6483,13 @@ regcomp (regex_t *__restrict preg, const char *__restrict pattern,
preg->used = 0;
/* Try to allocate space for the fastmap. */
- preg->fastmap = (char *) malloc (1 << BYTEWIDTH);
+ preg->fastmap = malloc (1 << BYTEWIDTH);
if (cflags & REG_ICASE)
{
unsigned i;
- preg->translate
- = (RE_TRANSLATE_TYPE) malloc (CHAR_SET_SIZE
- * sizeof (*(RE_TRANSLATE_TYPE)0));
+ preg->translate = malloc (CHAR_SET_SIZE * sizeof *preg->translate);
if (preg->translate == NULL)
return (int) REG_ESPACE;