diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2012-07-05 11:35:48 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2012-07-05 11:35:48 -0700 |
commit | 38182d901d030c7d65f4aa7a49b583afb30eb9b7 (patch) | |
tree | a69e1a571495d6ca1c034359d7c995639774ab9b | |
parent | 6dd5a677dbf794eedaa8325c46d57ac041373361 (diff) | |
download | emacs-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.
-rw-r--r-- | src/ChangeLog | 25 | ||||
-rw-r--r-- | src/alloc.c | 75 | ||||
-rw-r--r-- | src/bidi.c | 3 | ||||
-rw-r--r-- | src/buffer.c | 21 | ||||
-rw-r--r-- | src/buffer.h | 4 | ||||
-rw-r--r-- | src/bytecode.c | 3 | ||||
-rw-r--r-- | src/callint.c | 8 | ||||
-rw-r--r-- | src/callproc.c | 6 | ||||
-rw-r--r-- | src/charset.c | 2 | ||||
-rw-r--r-- | src/coding.c | 8 | ||||
-rw-r--r-- | src/composite.c | 2 | ||||
-rw-r--r-- | src/data.c | 3 | ||||
-rw-r--r-- | src/dispnew.c | 33 | ||||
-rw-r--r-- | src/doc.c | 9 | ||||
-rw-r--r-- | src/editfns.c | 18 | ||||
-rw-r--r-- | src/emacs.c | 2 | ||||
-rw-r--r-- | src/eval.c | 5 | ||||
-rw-r--r-- | src/fileio.c | 26 | ||||
-rw-r--r-- | src/filelock.c | 2 | ||||
-rw-r--r-- | src/fns.c | 2 | ||||
-rw-r--r-- | src/font.c | 4 | ||||
-rw-r--r-- | src/fontset.c | 10 | ||||
-rw-r--r-- | src/frame.c | 33 | ||||
-rw-r--r-- | src/fringe.c | 15 | ||||
-rw-r--r-- | src/ftfont.c | 13 | ||||
-rw-r--r-- | src/ftxfont.c | 2 | ||||
-rw-r--r-- | src/gmalloc.c | 6 | ||||
-rw-r--r-- | src/gtkutil.c | 8 | ||||
-rw-r--r-- | src/image.c | 19 | ||||
-rw-r--r-- | src/keyboard.c | 38 | ||||
-rw-r--r-- | src/keymap.c | 6 | ||||
-rw-r--r-- | src/lread.c | 14 | ||||
-rw-r--r-- | src/macros.c | 6 | ||||
-rw-r--r-- | src/menu.c | 5 | ||||
-rw-r--r-- | src/nsfns.m | 3 | ||||
-rw-r--r-- | src/nsfont.m | 20 | ||||
-rw-r--r-- | src/nsmenu.m | 17 | ||||
-rw-r--r-- | src/nsterm.m | 32 | ||||
-rw-r--r-- | src/print.c | 3 | ||||
-rw-r--r-- | src/process.c | 14 | ||||
-rw-r--r-- | src/ralloc.c | 2 | ||||
-rw-r--r-- | src/regex.c | 43 | ||||
-rw-r--r-- | src/region-cache.c | 2 | ||||
-rw-r--r-- | src/scroll.c | 10 | ||||
-rw-r--r-- | src/search.c | 14 | ||||
-rw-r--r-- | src/sound.c | 16 | ||||
-rw-r--r-- | src/syntax.c | 4 | ||||
-rw-r--r-- | src/sysdep.c | 16 | ||||
-rw-r--r-- | src/term.c | 10 | ||||
-rw-r--r-- | src/termcap.c | 4 | ||||
-rw-r--r-- | src/unexmacosx.c | 8 | ||||
-rw-r--r-- | src/window.c | 5 | ||||
-rw-r--r-- | src/xdisp.c | 28 | ||||
-rw-r--r-- | src/xfaces.c | 23 | ||||
-rw-r--r-- | src/xfns.c | 14 | ||||
-rw-r--r-- | src/xftfont.c | 2 | ||||
-rw-r--r-- | src/xgselect.c | 2 | ||||
-rw-r--r-- | src/xmenu.c | 18 | ||||
-rw-r--r-- | src/xrdb.c | 12 | ||||
-rw-r--r-- | src/xselect.c | 45 | ||||
-rw-r--r-- | src/xterm.c | 19 |
61 files changed, 380 insertions, 442 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 1fdeee52f7f..d3035fe22a2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,28 @@ +2012-07-05 Paul Eggert <eggert@cs.ucla.edu> + + 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. + 2012-07-05 Eli Zaretskii <eliz@gnu.org> * xdisp.c (display_line): Fix horizontal pixel coordinates when diff --git a/src/alloc.c b/src/alloc.c index 6ef0782ca1b..695d71c6c94 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -615,7 +615,7 @@ overrun_check_malloc (size_t size) if (SIZE_MAX - overhead < size) abort (); - val = (unsigned char *) malloc (size + overhead); + val = malloc (size + overhead); if (val && check_depth == 1) { memcpy (val, xmalloc_overrun_check_header, XMALLOC_OVERRUN_CHECK_SIZE); @@ -923,7 +923,7 @@ lisp_malloc (size_t nbytes, enum mem_type type) allocated_mem_type = type; #endif - val = (void *) malloc (nbytes); + val = malloc (nbytes); #if ! USE_LSB_TAG /* If the memory just allocated cannot be addressed thru a Lisp @@ -1309,7 +1309,7 @@ emacs_blocked_malloc (size_t size, const void *ptr) __malloc_extra_blocks = malloc_hysteresis; #endif - value = (void *) malloc (size); + value = malloc (size); #ifdef GC_MALLOC_CHECK { @@ -1371,7 +1371,7 @@ emacs_blocked_realloc (void *ptr, size_t size, const void *ptr2) dont_register_blocks = 1; #endif /* GC_MALLOC_CHECK */ - value = (void *) realloc (ptr, size); + value = realloc (ptr, size); #ifdef GC_MALLOC_CHECK dont_register_blocks = 0; @@ -1523,10 +1523,8 @@ make_interval (void) { if (interval_block_index == INTERVAL_BLOCK_SIZE) { - register struct interval_block *newi; - - newi = (struct interval_block *) lisp_malloc (sizeof *newi, - MEM_TYPE_NON_LISP); + struct interval_block *newi + = lisp_malloc (sizeof *newi, MEM_TYPE_NON_LISP); newi->next = interval_block; interval_block = newi; @@ -1932,10 +1930,9 @@ allocate_string (void) add all the Lisp_Strings in it to the free-list. */ if (string_free_list == NULL) { - struct string_block *b; + struct string_block *b = lisp_malloc (sizeof *b, MEM_TYPE_STRING); int i; - b = (struct string_block *) lisp_malloc (sizeof *b, MEM_TYPE_STRING); b->next = string_blocks; string_blocks = b; @@ -2021,7 +2018,7 @@ allocate_string_data (struct Lisp_String *s, mallopt (M_MMAP_MAX, 0); #endif - b = (struct sblock *) lisp_malloc (size + GC_STRING_EXTRA, MEM_TYPE_NON_LISP); + b = lisp_malloc (size + GC_STRING_EXTRA, MEM_TYPE_NON_LISP); #ifdef DOUG_LEA_MALLOC /* Back to a reasonable maximum of mmap'ed areas. */ @@ -2039,7 +2036,7 @@ allocate_string_data (struct Lisp_String *s, < (needed + GC_STRING_EXTRA))) { /* Not enough room in the current sblock. */ - b = (struct sblock *) lisp_malloc (SBLOCK_SIZE, MEM_TYPE_NON_LISP); + b = lisp_malloc (SBLOCK_SIZE, MEM_TYPE_NON_LISP); b->next_free = &b->first_data; b->first_data.string = NULL; b->next = NULL; @@ -2619,10 +2616,8 @@ make_float (double float_value) { if (float_block_index == FLOAT_BLOCK_SIZE) { - register struct float_block *new; - - new = (struct float_block *) lisp_align_malloc (sizeof *new, - MEM_TYPE_FLOAT); + struct float_block *new + = lisp_align_malloc (sizeof *new, MEM_TYPE_FLOAT); new->next = float_block; memset (new->gcmarkbits, 0, sizeof new->gcmarkbits); float_block = new; @@ -2738,9 +2733,8 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0, { if (cons_block_index == CONS_BLOCK_SIZE) { - register struct cons_block *new; - new = (struct cons_block *) lisp_align_malloc (sizeof *new, - MEM_TYPE_CONS); + struct cons_block *new + = lisp_align_malloc (sizeof *new, MEM_TYPE_CONS); memset (new->gcmarkbits, 0, sizeof new->gcmarkbits); new->next = cons_block; cons_block = new; @@ -2972,7 +2966,7 @@ static struct Lisp_Vector *zero_vector; static struct vector_block * allocate_vector_block (void) { - struct vector_block *block = xmalloc (sizeof (struct vector_block)); + struct vector_block *block = xmalloc (sizeof *block); #if GC_MARK_STACK && !defined GC_MALLOC_CHECK mem_insert (block->data, block->data + VECTOR_BLOCK_BYTES, @@ -3198,7 +3192,7 @@ allocate_vectorlike (ptrdiff_t len) p = allocate_vector_from_block (vroundup (nbytes)); else { - p = (struct Lisp_Vector *) lisp_malloc (nbytes, MEM_TYPE_VECTORLIKE); + p = lisp_malloc (nbytes, MEM_TYPE_VECTORLIKE); p->header.next.vector = large_vectors; large_vectors = p; } @@ -3253,7 +3247,7 @@ allocate_pseudovector (int memlen, int lisplen, int tag) struct buffer * allocate_buffer (void) { - struct buffer *b = lisp_malloc (sizeof (struct buffer), MEM_TYPE_BUFFER); + struct buffer *b = lisp_malloc (sizeof *b, MEM_TYPE_BUFFER); XSETPVECTYPESIZE (b, PVEC_BUFFER, (offsetof (struct buffer, own_text) - header_size) / word_size); @@ -3487,9 +3481,8 @@ Its value and function definition are void, and its property list is nil. */) { if (symbol_block_index == SYMBOL_BLOCK_SIZE) { - struct symbol_block *new; - new = (struct symbol_block *) lisp_malloc (sizeof *new, - MEM_TYPE_SYMBOL); + struct symbol_block *new + = lisp_malloc (sizeof *new, MEM_TYPE_SYMBOL); new->next = symbol_block; symbol_block = new; symbol_block_index = 0; @@ -3580,9 +3573,7 @@ allocate_misc (void) { if (marker_block_index == MARKER_BLOCK_SIZE) { - struct marker_block *new; - new = (struct marker_block *) lisp_malloc (sizeof *new, - MEM_TYPE_MISC); + struct marker_block *new = lisp_malloc (sizeof *new, MEM_TYPE_MISC); new->next = marker_block; marker_block = new; marker_block_index = 0; @@ -3775,25 +3766,25 @@ refill_memory_reserve (void) { #ifndef SYSTEM_MALLOC if (spare_memory[0] == 0) - spare_memory[0] = (char *) malloc (SPARE_MEMORY); + spare_memory[0] = malloc (SPARE_MEMORY); if (spare_memory[1] == 0) - spare_memory[1] = (char *) lisp_align_malloc (sizeof (struct cons_block), + spare_memory[1] = lisp_align_malloc (sizeof (struct cons_block), MEM_TYPE_CONS); if (spare_memory[2] == 0) - spare_memory[2] = (char *) lisp_align_malloc (sizeof (struct cons_block), - MEM_TYPE_CONS); + spare_memory[2] = lisp_align_malloc (sizeof (struct cons_block), + MEM_TYPE_CONS); if (spare_memory[3] == 0) - spare_memory[3] = (char *) lisp_align_malloc (sizeof (struct cons_block), - MEM_TYPE_CONS); + spare_memory[3] = lisp_align_malloc (sizeof (struct cons_block), + MEM_TYPE_CONS); if (spare_memory[4] == 0) - spare_memory[4] = (char *) lisp_align_malloc (sizeof (struct cons_block), - MEM_TYPE_CONS); + spare_memory[4] = lisp_align_malloc (sizeof (struct cons_block), + MEM_TYPE_CONS); if (spare_memory[5] == 0) - spare_memory[5] = (char *) lisp_malloc (sizeof (struct string_block), - MEM_TYPE_STRING); + spare_memory[5] = lisp_malloc (sizeof (struct string_block), + MEM_TYPE_STRING); if (spare_memory[6] == 0) - spare_memory[6] = (char *) lisp_malloc (sizeof (struct string_block), - MEM_TYPE_STRING); + spare_memory[6] = lisp_malloc (sizeof (struct string_block), + MEM_TYPE_STRING); if (spare_memory[0] && spare_memory[1] && spare_memory[5]) Vmemory_full = Qnil; #endif @@ -3893,7 +3884,7 @@ mem_insert (void *start, void *end, enum mem_type type) /* Create a new node. */ #ifdef GC_MALLOC_CHECK - x = (struct mem_node *) _malloc_internal (sizeof *x); + x = _malloc_internal (sizeof *x); if (x == NULL) abort (); #else @@ -5441,7 +5432,7 @@ See Info node `(elisp)Garbage Collection'. */) { if (stack_copy_size < stack_size) { - stack_copy = (char *) xrealloc (stack_copy, stack_size); + stack_copy = xrealloc (stack_copy, stack_size); stack_copy_size = stack_size; } memcpy (stack_copy, stack, stack_size); diff --git a/src/bidi.c b/src/bidi.c index 80986e5b671..0fa1cc2b0e2 100644 --- a/src/bidi.c +++ b/src/bidi.c @@ -361,8 +361,7 @@ bidi_cache_shrink (void) { if (bidi_cache_size > BIDI_CACHE_CHUNK) { - bidi_cache - = (struct bidi_it *) xrealloc (bidi_cache, BIDI_CACHE_CHUNK * elsz); + bidi_cache = xrealloc (bidi_cache, BIDI_CACHE_CHUNK * elsz); bidi_cache_size = BIDI_CACHE_CHUNK; } bidi_cache_reset (); diff --git a/src/buffer.c b/src/buffer.c index e1c33f4c711..838932db4df 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -2793,11 +2793,11 @@ mouse_face_overlay_overlaps (Lisp_Object overlay) Lisp_Object *v, tem; size = 10; - v = (Lisp_Object *) alloca (size * sizeof *v); + v = alloca (size * sizeof *v); n = overlays_in (start, end, 0, &v, &size, NULL, NULL); if (n > size) { - v = (Lisp_Object *) alloca (n * sizeof *v); + v = alloca (n * sizeof *v); overlays_in (start, end, 0, &v, &n, NULL, NULL); } @@ -2885,8 +2885,7 @@ ptrdiff_t sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w) { ptrdiff_t i, j; - struct sortvec *sortvec; - sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec)); + struct sortvec *sortvec = alloca (noverlays * sizeof *sortvec); /* Put the valid and relevant overlays into sortvec. */ @@ -3893,7 +3892,7 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0, len = 10; /* We can't use alloca here because overlays_at can call xrealloc. */ - overlay_vec = xmalloc (len * sizeof (Lisp_Object)); + overlay_vec = xmalloc (len * sizeof *overlay_vec); /* Put all the overlays we want in a vector in overlay_vec. Store the length in len. */ @@ -3924,7 +3923,7 @@ end of the buffer. */) CHECK_NUMBER_COERCE_MARKER (end); len = 10; - overlay_vec = xmalloc (len * sizeof (Lisp_Object)); + overlay_vec = xmalloc (len * sizeof *overlay_vec); /* Put all the overlays we want in a vector in overlay_vec. Store the length in len. */ @@ -3952,7 +3951,7 @@ the value is (point-max). */) CHECK_NUMBER_COERCE_MARKER (pos); len = 10; - overlay_vec = xmalloc (len * sizeof (Lisp_Object)); + overlay_vec = xmalloc (len * sizeof *overlay_vec); /* Put all the overlays we want in a vector in overlay_vec. Store the length in len. @@ -3996,7 +3995,7 @@ the value is (point-min). */) return pos; len = 10; - overlay_vec = xmalloc (len * sizeof (Lisp_Object)); + overlay_vec = xmalloc (len * sizeof *overlay_vec); /* Put all the overlays we want in a vector in overlay_vec. Store the length in len. @@ -4251,7 +4250,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after, First copy the vector contents, in case some of these hooks do subsequent modification of the buffer. */ ptrdiff_t size = last_overlay_modification_hooks_used; - Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object)); + Lisp_Object *copy = alloca (size * sizeof *copy); ptrdiff_t i; memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, @@ -4873,7 +4872,7 @@ init_buffer_once (void) /* If you add, remove, or reorder Lisp_Objects in a struct buffer, make sure that this is still correct. Otherwise, mark_vectorlike may not trace all Lisp_Objects in buffer_defaults and buffer_local_symbols. */ - const int pvecsize + const int pvecsize = (offsetof (struct buffer, own_text) - sizeof (struct vectorlike_header)) / sizeof (Lisp_Object); @@ -5089,7 +5088,7 @@ init_buffer (void) if (!(IS_DIRECTORY_SEP (pwd[len - 1]))) { /* Grow buffer to add directory separator and '\0'. */ - pwd = (char *) realloc (pwd, len + 2); + pwd = realloc (pwd, len + 2); if (!pwd) fatal ("`get_current_dir_name' failed: %s\n", strerror (errno)); pwd[len] = DIRECTORY_SEP; diff --git a/src/buffer.h b/src/buffer.h index b58c5c165e1..0615f85bfe6 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -918,13 +918,13 @@ extern void mmap_set_vars (int); #define GET_OVERLAYS_AT(posn, overlays, noverlays, nextp, chrq) \ do { \ ptrdiff_t maxlen = 40; \ - overlays = (Lisp_Object *) alloca (maxlen * sizeof (Lisp_Object)); \ + overlays = alloca (maxlen * sizeof *overlays); \ noverlays = overlays_at (posn, 0, &overlays, &maxlen, \ nextp, NULL, chrq); \ if (noverlays > maxlen) \ { \ maxlen = noverlays; \ - overlays = (Lisp_Object *) alloca (maxlen * sizeof (Lisp_Object)); \ + overlays = alloca (maxlen * sizeof *overlays); \ noverlays = overlays_at (posn, 0, &overlays, &maxlen, \ nextp, NULL, chrq); \ } \ diff --git a/src/bytecode.c b/src/bytecode.c index 08a02ea921d..e1363d390e8 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -488,8 +488,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, stack.constants = vector; if (MAX_ALLOCA / sizeof (Lisp_Object) <= XFASTINT (maxdepth)) memory_full (SIZE_MAX); - top = (Lisp_Object *) alloca ((XFASTINT (maxdepth) + 1) - * sizeof (Lisp_Object)); + top = alloca ((XFASTINT (maxdepth) + 1) * sizeof *top); #if BYTE_MAINTAIN_TOP stack.bottom = top + 1; stack.top = NULL; diff --git a/src/callint.c b/src/callint.c index e5ff99714c0..1a99ca2731c 100644 --- a/src/callint.c +++ b/src/callint.c @@ -331,7 +331,7 @@ invoke it. If KEYS is omitted or nil, the return value of { /* Make a copy of string so that if a GC relocates specs, `string' will still be valid. */ - string = (char *) alloca (SBYTES (specs) + 1); + string = alloca (SBYTES (specs) + 1); memcpy (string, SSDATA (specs), SBYTES (specs) + 1); } else @@ -469,9 +469,9 @@ invoke it. If KEYS is omitted or nil, the return value of < nargs) memory_full (SIZE_MAX); - args = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object)); - visargs = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object)); - varies = (signed char *) alloca (nargs); + args = alloca (nargs * sizeof *args); + visargs = alloca (nargs * sizeof *visargs); + varies = alloca (nargs * sizeof *varies); for (i = 0; i < nargs; i++) { diff --git a/src/callproc.c b/src/callproc.c index 0418e4e8cd5..39fcb99c4b5 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -1174,7 +1174,7 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L on that. */ pwd_var = xmalloc (i + 6); #else - pwd_var = (char *) alloca (i + 6); + pwd_var = alloca (i + 6); #endif temp = pwd_var + 4; memcpy (pwd_var, "PWD=", 4); @@ -1242,7 +1242,7 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L } /* new_length + 2 to include PWD and terminating 0. */ - env = new_env = (char **) alloca ((new_length + 2) * sizeof (char *)); + env = new_env = alloca ((new_length + 2) * sizeof *env); /* If we have a PWD envvar, pass one down, but with corrected value. */ if (egetenv ("PWD")) @@ -1250,7 +1250,7 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L if (STRINGP (display)) { - char *vdata = (char *) alloca (sizeof "DISPLAY=" + SBYTES (display)); + char *vdata = alloca (sizeof "DISPLAY=" + SBYTES (display)); strcpy (vdata, "DISPLAY="); strcat (vdata, SSDATA (display)); new_env = add_env (env, new_env, vdata); diff --git a/src/charset.c b/src/charset.c index a0ed9673e98..4c47ba45fb6 100644 --- a/src/charset.c +++ b/src/charset.c @@ -294,7 +294,7 @@ load_charset_map (struct charset *charset, struct charset_map_entries *entries, else { if (! temp_charset_work) - temp_charset_work = xmalloc (sizeof (*temp_charset_work)); + temp_charset_work = xmalloc (sizeof *temp_charset_work); if (control_flag == 1) { memset (temp_charset_work->table.decoder, -1, diff --git a/src/coding.c b/src/coding.c index 891fea09abf..4b2a9740121 100644 --- a/src/coding.c +++ b/src/coding.c @@ -1145,8 +1145,8 @@ coding_alloc_by_realloc (struct coding_system *coding, ptrdiff_t bytes) { if (STRING_BYTES_BOUND - coding->dst_bytes < bytes) string_overflow (); - coding->destination = (unsigned char *) xrealloc (coding->destination, - coding->dst_bytes + bytes); + coding->destination = xrealloc (coding->destination, + coding->dst_bytes + bytes); coding->dst_bytes += bytes; } @@ -7010,7 +7010,7 @@ produce_charset (struct coding_system *coding, int *charbuf, ptrdiff_t pos) coding->charbuf = NULL; \ while (size > 1024) \ { \ - coding->charbuf = (int *) alloca (sizeof (int) * size); \ + coding->charbuf = alloca (sizeof (int) * size); \ if (coding->charbuf) \ break; \ size >>= 1; \ @@ -9568,7 +9568,7 @@ make_subsidiaries (Lisp_Object base) { Lisp_Object subsidiaries; ptrdiff_t base_name_len = SBYTES (SYMBOL_NAME (base)); - char *buf = (char *) alloca (base_name_len + 6); + char *buf = alloca (base_name_len + 6); int i; memcpy (buf, SDATA (SYMBOL_NAME (base)), base_name_len); diff --git a/src/composite.c b/src/composite.c index 464b55202d7..87fad6fa18f 100644 --- a/src/composite.c +++ b/src/composite.c @@ -326,7 +326,7 @@ get_composition_id (ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t nchars, memory_full (SIZE_MAX); /* Register the composition in composition_table. */ - cmp = xmalloc (sizeof (struct composition)); + cmp = xmalloc (sizeof *cmp); cmp->method = method; cmp->hash_index = hash_index; diff --git a/src/data.c b/src/data.c index fe7b9420344..faa87d0013f 100644 --- a/src/data.c +++ b/src/data.c @@ -1463,8 +1463,7 @@ union Lisp_Val_Fwd static struct Lisp_Buffer_Local_Value * make_blv (struct Lisp_Symbol *sym, int forwarded, union Lisp_Val_Fwd valcontents) { - struct Lisp_Buffer_Local_Value *blv - = xmalloc (sizeof (struct Lisp_Buffer_Local_Value)); + struct Lisp_Buffer_Local_Value *blv = xmalloc (sizeof *blv); Lisp_Object symbol; Lisp_Object tem; diff --git a/src/dispnew.c b/src/dispnew.c index 17bd2e828fa..5c6ea0123be 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -2023,9 +2023,7 @@ static struct glyph_matrix * save_current_matrix (struct frame *f) { int i; - struct glyph_matrix *saved; - - saved = xzalloc (sizeof *saved); + struct glyph_matrix *saved = xzalloc (sizeof *saved); saved->nrows = f->current_matrix->nrows; saved->rows = xzalloc (saved->nrows * sizeof *saved->rows); @@ -2243,16 +2241,8 @@ adjust_frame_glyphs_for_window_redisplay (struct frame *f) static void adjust_frame_message_buffer (struct frame *f) { - ptrdiff_t size = FRAME_MESSAGE_BUF_SIZE (f) + 1; - - if (FRAME_MESSAGE_BUF (f)) - { - char *buffer = FRAME_MESSAGE_BUF (f); - char *new_buffer = (char *) xrealloc (buffer, size); - FRAME_MESSAGE_BUF (f) = new_buffer; - } - else - FRAME_MESSAGE_BUF (f) = xmalloc (size); + FRAME_MESSAGE_BUF (f) = xrealloc (FRAME_MESSAGE_BUF (f), + FRAME_MESSAGE_BUF_SIZE (f) + 1); } @@ -2261,9 +2251,8 @@ adjust_frame_message_buffer (struct frame *f) static void adjust_decode_mode_spec_buffer (struct frame *f) { - f->decode_mode_spec_buffer - = (char *) xrealloc (f->decode_mode_spec_buffer, - FRAME_MESSAGE_BUF_SIZE (f) + 1); + f->decode_mode_spec_buffer = xrealloc (f->decode_mode_spec_buffer, + FRAME_MESSAGE_BUF_SIZE (f) + 1); } @@ -2810,7 +2799,7 @@ mirrored_line_dance (struct glyph_matrix *matrix, int unchanged_at_top, int nlin int i; /* Make a copy of the original rows. */ - old_rows = (struct glyph_row *) alloca (nlines * sizeof *old_rows); + old_rows = alloca (nlines * sizeof *old_rows); memcpy (old_rows, new_rows, nlines * sizeof *old_rows); /* Assign new rows, maybe clear lines. */ @@ -2928,7 +2917,7 @@ mirror_line_dance (struct window *w, int unchanged_at_top, int nlines, int *copy struct glyph_row *old_rows; /* Make a copy of the original rows of matrix m. */ - old_rows = (struct glyph_row *) alloca (m->nrows * sizeof *old_rows); + old_rows = alloca (m->nrows * sizeof *old_rows); memcpy (old_rows, m->rows, m->nrows * sizeof *old_rows); for (i = 0; i < nlines; ++i) @@ -4845,10 +4834,10 @@ scrolling (struct frame *frame) int unchanged_at_top, unchanged_at_bottom; int window_size; int changed_lines; - int *old_hash = (int *) alloca (FRAME_LINES (frame) * sizeof (int)); - int *new_hash = (int *) alloca (FRAME_LINES (frame) * sizeof (int)); - int *draw_cost = (int *) alloca (FRAME_LINES (frame) * sizeof (int)); - int *old_draw_cost = (int *) alloca (FRAME_LINES (frame) * sizeof (int)); + int *old_hash = alloca (FRAME_LINES (frame) * sizeof (int)); + int *new_hash = alloca (FRAME_LINES (frame) * sizeof (int)); + int *draw_cost = alloca (FRAME_LINES (frame) * sizeof (int)); + int *old_draw_cost = alloca (FRAME_LINES (frame) * sizeof (int)); register int i; int free_at_end_vpos = FRAME_LINES (frame); struct glyph_matrix *current_matrix = frame->current_matrix; diff --git a/src/doc.c b/src/doc.c index 54d028ab61c..6b356d57cb3 100644 --- a/src/doc.c +++ b/src/doc.c @@ -577,14 +577,13 @@ the same file name is found in the `doc-directory'. */) (0) #endif /* CANNOT_DUMP */ { - name = (char *) alloca (SCHARS (filename) + 14); + name = alloca (SCHARS (filename) + 14); strcpy (name, "../etc/"); } else { CHECK_STRING (Vdoc_directory); - name = (char *) alloca (SCHARS (filename) - + SCHARS (Vdoc_directory) + 1); + name = alloca (SCHARS (filename) + SCHARS (Vdoc_directory) + 1); strcpy (name, SSDATA (Vdoc_directory)); } strcat (name, SSDATA (filename)); /*** Add this line ***/ @@ -828,7 +827,7 @@ Otherwise, return a new string, without any text properties. */) ptrdiff_t offset = bufp - buf; if (STRING_BYTES_BOUND - 4 < bsize) string_overflow (); - buf = (char *) xrealloc (buf, bsize += 4); + buf = xrealloc (buf, bsize += 4); bufp = buf + offset; memcpy (bufp, "M-x ", 4); bufp += 4; @@ -924,7 +923,7 @@ Otherwise, return a new string, without any text properties. */) ptrdiff_t offset = bufp - buf; if (STRING_BYTES_BOUND - length_byte < bsize) string_overflow (); - buf = (char *) xrealloc (buf, bsize += length_byte); + buf = xrealloc (buf, bsize += length_byte); bufp = buf + offset; memcpy (bufp, start, length_byte); bufp += length_byte; diff --git a/src/editfns.c b/src/editfns.c index 5ca68d4f37a..d4146cefb92 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -397,14 +397,14 @@ get_pos_property (Lisp_Object position, register Lisp_Object prop, Lisp_Object o /* First try with room for 40 overlays. */ noverlays = 40; - overlay_vec = (Lisp_Object *) alloca (noverlays * sizeof (Lisp_Object)); + overlay_vec = alloca (noverlays * sizeof *overlay_vec); noverlays = overlays_around (posn, overlay_vec, noverlays); /* If there are more than 40, make enough space for all, and try again. */ if (noverlays > 40) { - overlay_vec = (Lisp_Object *) alloca (noverlays * sizeof (Lisp_Object)); + overlay_vec = alloca (noverlays * sizeof *overlay_vec); noverlays = overlays_around (posn, overlay_vec, noverlays); } noverlays = sort_overlays (overlay_vec, noverlays, NULL); @@ -1330,7 +1330,7 @@ name, or nil if there is no such user. */) Lisp_Object login; login = Fuser_login_name (make_number (pw->pw_uid)); - r = (char *) alloca (strlen (p) + SCHARS (login) + 1); + r = alloca (strlen (p) + SCHARS (login) + 1); memcpy (r, p, q - p); r[q - p] = 0; strcat (r, SSDATA (login)); @@ -2154,7 +2154,7 @@ set_time_zone_rule (const char *tzstring) for (from = environ; *from; from++) continue; envptrs = from - environ + 2; - newenv = to = xmalloc (envptrs * sizeof (char *) + newenv = to = xmalloc (envptrs * sizeof *newenv + (tzstring ? strlen (tzstring) + 4 : 0)); /* Add TZSTRING to the end of environ, as a value for TZ. */ @@ -3472,15 +3472,11 @@ usage: (message-box FORMAT-STRING &rest ARGS) */) } #endif /* HAVE_MENUS */ /* Copy the data so that it won't move when we GC. */ - if (! message_text) - { - message_text = xmalloc (80); - message_length = 80; - } if (SBYTES (val) > message_length) { - message_text = (char *) xrealloc (message_text, SBYTES (val)); - message_length = SBYTES (val); + ptrdiff_t new_length = SBYTES (val) + 80; + message_text = xrealloc (message_text, new_length); + message_length = new_length; } memcpy (message_text, SDATA (val), SBYTES (val)); message2 (message_text, SBYTES (val), diff --git a/src/emacs.c b/src/emacs.c index 6a7e9299b36..bdc92f88e8e 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1820,7 +1820,7 @@ static const struct standard_args standard_args[] = static void sort_args (int argc, char **argv) { - char **new = xmalloc (sizeof (char *) * argc); + char **new = xmalloc (argc * sizeof *new); /* For each element of argv, the corresponding element of options is: 0 for an option that takes no arguments, diff --git a/src/eval.c b/src/eval.c index d35b71530ac..9da9ec05cae 100644 --- a/src/eval.c +++ b/src/eval.c @@ -138,7 +138,7 @@ void init_eval_once (void) { enum { size = 50 }; - specpdl = xmalloc (size * sizeof (struct specbinding)); + specpdl = xmalloc (size * sizeof *specpdl); specpdl_size = size; specpdl_ptr = specpdl; /* Don't forget to update docs (lispref node "Local Variables"). */ @@ -2803,7 +2803,8 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */) { if (XSUBR (fun)->max_args > numargs) { - internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object)); + internal_args = alloca (XSUBR (fun)->max_args + * sizeof *internal_args); memcpy (internal_args, args + 1, numargs * sizeof (Lisp_Object)); for (i = numargs; i < XSUBR (fun)->max_args; i++) internal_args[i] = Qnil; diff --git a/src/fileio.c b/src/fileio.c index 69ec7b05392..0f6a1d5f799 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -336,7 +336,7 @@ Given a Unix syntax file name, returns a string ending in slash. */) filename = FILE_SYSTEM_CASE (filename); #ifdef DOS_NT - beg = (char *) alloca (SBYTES (filename) + 1); + beg = alloca (SBYTES (filename) + 1); memcpy (beg, SSDATA (filename), SBYTES (filename) + 1); #else beg = SSDATA (filename); @@ -510,7 +510,7 @@ For a Unix-syntax file name, just appends a slash. */) error ("Invalid handler in `file-name-handler-alist'"); } - buf = (char *) alloca (SBYTES (file) + 10); + buf = alloca (SBYTES (file) + 10); file_name_as_directory (buf, SSDATA (file)); return make_specified_string (buf, -1, strlen (buf), STRING_MULTIBYTE (file)); @@ -575,7 +575,7 @@ In Unix-syntax, this function just removes the final slash. */) error ("Invalid handler in `file-name-handler-alist'"); } - buf = (char *) alloca (SBYTES (directory) + 20); + buf = alloca (SBYTES (directory) + 20); directory_file_name (SSDATA (directory), buf); return make_specified_string (buf, -1, strlen (buf), STRING_MULTIBYTE (directory)); @@ -878,7 +878,7 @@ filesystem tree, not (expand-file-name ".." dirname). */) } /* Make a local copy of nm[] to protect it from GC in DECODE_FILE below. */ - nm = (char *) alloca (SBYTES (name) + 1); + nm = alloca (SBYTES (name) + 1); memcpy (nm, SSDATA (name), SBYTES (name) + 1); #ifdef DOS_NT @@ -1186,7 +1186,7 @@ filesystem tree, not (expand-file-name ".." dirname). */) #endif ) { - char *temp = (char *) alloca (length); + char *temp = alloca (length); memcpy (temp, newdir, length - 1); temp[length - 1] = 0; newdir = temp; @@ -1202,10 +1202,10 @@ filesystem tree, not (expand-file-name ".." dirname). */) /* Reserve space for drive specifier and escape prefix, since either or both may need to be inserted. (The Microsoft x86 compiler produces incorrect code if the following two lines are combined.) */ - target = (char *) alloca (tlen + 4); + target = alloca (tlen + 4); target += 4; #else /* not DOS_NT */ - target = (char *) alloca (tlen); + target = alloca (tlen); #endif /* not DOS_NT */ *target = 0; @@ -1415,7 +1415,7 @@ See also the function `substitute-in-file-name'.") unsigned char *ptr = (unsigned char *) strchr (user, '/'); ptrdiff_t len = ptr ? ptr - user : strlen (user); /* Copy the user name into temp storage. */ - o = (unsigned char *) alloca (len + 1); + o = alloca (len + 1); memcpy (o, user, len); o[len] = 0; @@ -1443,7 +1443,7 @@ See also the function `substitute-in-file-name'.") /* Now concatenate the directory and name to new space in the stack frame. */ tlen = (newdir ? strlen (newdir) + 1 : 0) + strlen (nm) + 1; - target = (unsigned char *) alloca (tlen); + target = alloca (tlen); *target = 0; if (newdir) @@ -1593,7 +1593,7 @@ those `/' is discarded. */) /* Always work on a copy of the string, in case GC happens during decode of environment variables, causing the original Lisp_String data to be relocated. */ - nm = (char *) alloca (SBYTES (filename) + 1); + nm = alloca (SBYTES (filename) + 1); memcpy (nm, SDATA (filename), SBYTES (filename) + 1); #ifdef DOS_NT @@ -1645,7 +1645,7 @@ those `/' is discarded. */) } /* Copy out the variable name. */ - target = (char *) alloca (s - o + 1); + target = alloca (s - o + 1); strncpy (target, o, s - o); target[s - o] = 0; #ifdef DOS_NT @@ -1676,7 +1676,7 @@ those `/' is discarded. */) /* If substitution required, recopy the string and do it. */ /* Make space in stack frame for the new copy. */ - xnm = (char *) alloca (SBYTES (filename) + total + 1); + xnm = alloca (SBYTES (filename) + total + 1); x = xnm; /* Copy the rest of the name through, replacing $ constructs with values. */ @@ -1708,7 +1708,7 @@ those `/' is discarded. */) } /* Copy out the variable name. */ - target = (char *) alloca (s - o + 1); + target = alloca (s - o + 1); strncpy (target, o, s - o); target[s - o] = 0; #ifdef DOS_NT diff --git a/src/filelock.c b/src/filelock.c index 1497529c6e0..252ee3cfb1d 100644 --- a/src/filelock.c +++ b/src/filelock.c @@ -294,7 +294,7 @@ typedef struct trailing period plus one for the digit after it plus one for the null. */ #define MAKE_LOCK_NAME(lock, file) \ - (lock = (char *) alloca (SBYTES (file) + 2 + 1 + 1 + 1), \ + (lock = alloca (SBYTES (file) + 2 + 1 + 1 + 1), \ fill_in_lock_file_name (lock, (file))) static void diff --git a/src/fns.c b/src/fns.c index c2c33494149..c30c85f7b45 100644 --- a/src/fns.c +++ b/src/fns.c @@ -4347,7 +4347,7 @@ usage: (make-hash-table &rest KEYWORD-ARGS) */) /* The vector `used' is used to keep track of arguments that have been consumed. */ - used = (char *) alloca (nargs * sizeof *used); + used = alloca (nargs * sizeof *used); memset (used, 0, nargs * sizeof *used); /* See if there's a `:test TEST' among the arguments. */ diff --git a/src/font.c b/src/font.c index 555c76c73c8..4f0f814a583 100644 --- a/src/font.c +++ b/src/font.c @@ -3402,7 +3402,7 @@ register_font_driver (struct font_driver *driver, FRAME_PTR f) if (EQ (list->driver->type, driver->type)) error ("Duplicated font driver: %s", SDATA (SYMBOL_NAME (driver->type))); - list = xmalloc (sizeof (struct font_driver_list)); + list = xmalloc (sizeof *list); list->on = 0; list->driver = driver; list->next = NULL; @@ -3552,7 +3552,7 @@ font_put_frame_data (FRAME_PTR f, struct font_driver *driver, void *data) if (! list) { - list = xmalloc (sizeof (struct font_data_list)); + list = xmalloc (sizeof *list); list->driver = driver; list->next = f->font_data_list; f->font_data_list = list; diff --git a/src/fontset.c b/src/fontset.c index da54bca2a5c..cfaa24124f1 100644 --- a/src/fontset.c +++ b/src/fontset.c @@ -1082,9 +1082,9 @@ fontset_pattern_regexp (Lisp_Object pattern) we convert "*" to "[^-]*" which is much faster in regular expression matching. */ if (ndashes < 14) - p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 2 * nstars + 2 * nescs + 1); + p1 = regex = alloca (SBYTES (pattern) + 2 * nstars + 2 * nescs + 1); else - p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 5 * nstars + 2 * nescs + 1); + p1 = regex = alloca (SBYTES (pattern) + 5 * nstars + 2 * nescs + 1); *p1++ = '^'; for (p0 = SDATA (pattern); *p0; p0++) @@ -1893,8 +1893,7 @@ format is the same as above. */) /* Recode fontsets realized on FRAME from the base fontset FONTSET in the table `realized'. */ - realized[0] = (Lisp_Object *) alloca (sizeof (Lisp_Object) - * ASIZE (Vfontset_table)); + realized[0] = alloca (sizeof (Lisp_Object) * ASIZE (Vfontset_table)); for (i = j = 0; i < ASIZE (Vfontset_table); i++) { elt = FONTSET_FROM_ID (i); @@ -1905,8 +1904,7 @@ format is the same as above. */) } realized[0][j] = Qnil; - realized[1] = (Lisp_Object *) alloca (sizeof (Lisp_Object) - * ASIZE (Vfontset_table)); + realized[1] = alloca (sizeof (Lisp_Object) * ASIZE (Vfontset_table)); for (i = j = 0; ! NILP (realized[0][i]); i++) { elt = FONTSET_DEFAULT (realized[0][i]); diff --git a/src/frame.c b/src/frame.c index 6ff336c40ee..8db943bd0a5 100644 --- a/src/frame.c +++ b/src/frame.c @@ -647,7 +647,7 @@ affects all frames on the same terminal device. */) : NULL)); if (!NILP (tty)) { - name = (char *) alloca (SBYTES (tty) + 1); + name = alloca (SBYTES (tty) + 1); strncpy (name, SSDATA (tty), SBYTES (tty)); name[SBYTES (tty)] = 0; } @@ -658,7 +658,7 @@ affects all frames on the same terminal device. */) : NULL)); if (!NILP (tty_type)) { - type = (char *) alloca (SBYTES (tty_type) + 1); + type = alloca (SBYTES (tty_type) + 1); strncpy (type, SSDATA (tty_type), SBYTES (tty_type)); type[SBYTES (tty_type)] = 0; } @@ -2762,8 +2762,8 @@ x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist) for (tail = alist; CONSP (tail); tail = Fcdr (tail)) i++; - parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object)); - values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object)); + parms = alloca (i * sizeof *parms); + values = alloca (i * sizeof *values); /* Extract parm names and values into those vectors. */ @@ -3624,17 +3624,17 @@ xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Li /* Allocate space for the components, the dots which separate them, and the final '\0'. Make them big enough for the worst case. */ - name_key = (char *) alloca (SBYTES (Vx_resource_name) - + (STRINGP (component) - ? SBYTES (component) : 0) - + SBYTES (attribute) - + 3); - - class_key = (char *) alloca (SBYTES (Vx_resource_class) - + SBYTES (class) - + (STRINGP (subclass) - ? SBYTES (subclass) : 0) - + 3); + name_key = alloca (SBYTES (Vx_resource_name) + + (STRINGP (component) + ? SBYTES (component) : 0) + + SBYTES (attribute) + + 3); + + class_key = alloca (SBYTES (Vx_resource_class) + + SBYTES (class) + + (STRINGP (subclass) + ? SBYTES (subclass) : 0) + + 3); /* Start with emacs.FRAMENAME for the name (the specific one) and with `Emacs' for the class key (the general one). */ @@ -3710,8 +3710,7 @@ x_get_resource_string (const char *attribute, const char *class) /* Allocate space for the components, the dots which separate them, and the final '\0'. */ SAFE_ALLOCA (name_key, char *, invocation_namelen + strlen (attribute) + 2); - class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1) - + strlen (class) + 2); + class_key = alloca ((sizeof (EMACS_CLASS) - 1) + strlen (class) + 2); esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute); sprintf (class_key, "%s.%s", EMACS_CLASS, class); diff --git a/src/fringe.c b/src/fringe.c index cd3b87b43d4..4ab9c770326 100644 --- a/src/fringe.c +++ b/src/fringe.c @@ -1616,12 +1616,10 @@ If BITMAP already exists, the existing definition is replaced. */) error ("No free fringe bitmap slots"); i = max_fringe_bitmaps; - fringe_bitmaps - = ((struct fringe_bitmap **) - xrealloc (fringe_bitmaps, bitmaps * sizeof *fringe_bitmaps)); - fringe_faces - = (Lisp_Object *) xrealloc (fringe_faces, - bitmaps * sizeof *fringe_faces); + fringe_bitmaps = xrealloc (fringe_bitmaps, + bitmaps * sizeof *fringe_bitmaps); + fringe_faces = xrealloc (fringe_faces, + bitmaps * sizeof *fringe_faces); for (i = max_fringe_bitmaps; i < bitmaps; i++) { @@ -1803,9 +1801,8 @@ init_fringe (void) max_fringe_bitmaps = MAX_STANDARD_FRINGE_BITMAPS + 20; - fringe_bitmaps - = xzalloc (max_fringe_bitmaps * sizeof (struct fringe_bitmap *)); - fringe_faces = xmalloc (max_fringe_bitmaps * sizeof (Lisp_Object)); + fringe_bitmaps = xzalloc (max_fringe_bitmaps * sizeof *fringe_bitmaps); + fringe_faces = xmalloc (max_fringe_bitmaps * sizeof *fringe_faces); for (i = 0; i < max_fringe_bitmaps; i++) fringe_faces[i] = Qnil; diff --git a/src/ftfont.c b/src/ftfont.c index 29732e4c870..8e322369868 100644 --- a/src/ftfont.c +++ b/src/ftfont.c @@ -392,7 +392,7 @@ ftfont_lookup_cache (Lisp_Object key, enum ftfont_cache_for cache_for) args[1] = Qequal; ft_face_cache = Fmake_hash_table (2, args); } - cache_data = xmalloc (sizeof (struct ftfont_cache_data)); + cache_data = xmalloc (sizeof *cache_data); cache_data->ft_face = NULL; cache_data->fc_charset = NULL; val = make_save_value (NULL, 0); @@ -657,7 +657,7 @@ struct OpenTypeSpec static struct OpenTypeSpec * ftfont_get_open_type_spec (Lisp_Object otf_spec) { - struct OpenTypeSpec *spec = malloc (sizeof (struct OpenTypeSpec)); + struct OpenTypeSpec *spec = malloc (sizeof *spec); Lisp_Object val; int i, j, negative; @@ -696,7 +696,7 @@ ftfont_get_open_type_spec (Lisp_Object otf_spec) spec->features[i] = (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (int) < XINT (len) ? 0 - : malloc (sizeof (int) * XINT (len))); + : malloc (XINT (len) * sizeof *spec->features[i])); if (! spec->features[i]) { if (i > 0 && spec->features[0]) @@ -2460,15 +2460,16 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font, if (gstring.allocated == 0) { gstring.glyph_size = sizeof (MFLTGlyph); - gstring.glyphs = xnmalloc (len * 2, sizeof (MFLTGlyph)); + gstring.glyphs = xnmalloc (len * 2, sizeof *gstring.glyphs); gstring.allocated = len * 2; } else if (gstring.allocated < len * 2) { - gstring.glyphs = xnrealloc (gstring.glyphs, len * 2, sizeof (MFLTGlyph)); + gstring.glyphs = xnrealloc (gstring.glyphs, len * 2, + sizeof *gstring.glyphs); gstring.allocated = len * 2; } - memset (gstring.glyphs, 0, sizeof (MFLTGlyph) * len); + memset (gstring.glyphs, 0, len * sizeof *gstring.glyphs); for (i = 0; i < len; i++) { Lisp_Object g = LGSTRING_GLYPH (lgstring, i); diff --git a/src/ftxfont.c b/src/ftxfont.c index 9fe4d41dcc5..6ebe0798b4e 100644 --- a/src/ftxfont.c +++ b/src/ftxfont.c @@ -90,7 +90,7 @@ ftxfont_get_gcs (FRAME_PTR f, long unsigned int foreground, long unsigned int ba } } - new = malloc (sizeof (struct ftxfont_frame_data)); + new = malloc (sizeof *new); if (! new) return NULL; new->next = this; diff --git a/src/gmalloc.c b/src/gmalloc.c index 3de3733d55f..3739214bc46 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c @@ -1616,7 +1616,7 @@ memalign (size_t alignment, size_t size) break; if (l == NULL) { - l = malloc (sizeof (struct alignlist)); + l = malloc (sizeof *l); if (l != NULL) { l->next = _aligned_blocks; @@ -1811,7 +1811,7 @@ mallochook (size_t size) struct hdr *hdr; __malloc_hook = old_malloc_hook; - hdr = malloc (sizeof (struct hdr) + size + 1); + hdr = malloc (sizeof *hdr + size + 1); __malloc_hook = mallochook; if (hdr == NULL) return NULL; @@ -1842,7 +1842,7 @@ reallochook (void *ptr, size_t size) __free_hook = old_free_hook; __malloc_hook = old_malloc_hook; __realloc_hook = old_realloc_hook; - hdr = realloc (hdr, sizeof (struct hdr) + size + 1); + hdr = realloc (hdr, sizeof *hdr + size + 1); __free_hook = freehook; __malloc_hook = mallochook; __realloc_hook = reallochook; diff --git a/src/gtkutil.c b/src/gtkutil.c index 25a81c45436..82c7d643551 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -215,7 +215,7 @@ malloc_widget_value (void) } else { - wv = xmalloc (sizeof (widget_value)); + wv = xmalloc (sizeof *wv); malloc_cpt++; } memset (wv, 0, sizeof (widget_value)); @@ -2057,7 +2057,7 @@ make_cl_data (xg_menu_cb_data *cl_data, FRAME_PTR f, GCallback highlight_cb) { if (! cl_data) { - cl_data = xmalloc (sizeof (*cl_data)); + cl_data = xmalloc (sizeof *cl_data); cl_data->f = f; cl_data->menu_bar_vector = f->menu_bar_vector; cl_data->menu_bar_items_used = f->menu_bar_items_used; @@ -2357,7 +2357,7 @@ xg_create_one_menuitem (widget_value *item, if (utf8_label) g_free (utf8_label); if (utf8_key) g_free (utf8_key); - cb_data = xmalloc (sizeof (xg_menu_item_cb_data)); + cb_data = xmalloc (sizeof *cb_data); xg_list_insert (&xg_menu_item_cb_list, &cb_data->ptrs); @@ -4336,7 +4336,7 @@ is_box_type (GtkWidget *vb, int is_horizontal) { #ifdef HAVE_GTK3 int ret = 0; - if (GTK_IS_BOX (vb)) + if (GTK_IS_BOX (vb)) { GtkOrientation ori = gtk_orientable_get_orientation (GTK_ORIENTABLE (vb)); ret = (ori == GTK_ORIENTATION_HORIZONTAL && is_horizontal) diff --git a/src/image.c b/src/image.c index 45dcb554439..4877d262d00 100644 --- a/src/image.c +++ b/src/image.c @@ -1356,9 +1356,7 @@ x_alloc_image_color (struct frame *f, struct image *img, Lisp_Object color_name, /* This isn't called frequently so we get away with simply reallocating the color vector to the needed size, here. */ ptrdiff_t ncolors = img->ncolors + 1; - img->colors = - (unsigned long *) xrealloc (img->colors, - ncolors * sizeof *img->colors); + img->colors = xrealloc (img->colors, ncolors * sizeof *img->colors); img->colors[ncolors - 1] = color.pixel; img->ncolors = ncolors; result = color.pixel; @@ -2500,7 +2498,7 @@ w32_create_pixmap_from_bitmap_data (int width, int height, char *data) w1 = (width + 7) / 8; /* nb of 8bits elt in X bitmap */ w2 = ((width + 15) / 16) * 2; /* nb of 16bits elt in W32 bitmap */ - bits = (unsigned char *) alloca (height * w2); + bits = alloca (height * w2); memset (bits, 0, height * w2); for (i = 0; i < height; i++) { @@ -2927,7 +2925,7 @@ xbm_load (struct frame *f, struct image *img) char *p; int nbytes = (img->width + BITS_PER_CHAR - 1) / BITS_PER_CHAR; - p = bits = (char *) alloca (nbytes * img->height); + p = bits = alloca (nbytes * img->height); for (i = 0; i < img->height; ++i, p += nbytes) { Lisp_Object line = AREF (data, i); @@ -2950,7 +2948,7 @@ xbm_load (struct frame *f, struct image *img) invertedBits = bits; nbytes = (img->width + BITS_PER_CHAR - 1) / BITS_PER_CHAR * img->height; - bits = (char *) alloca (nbytes); + bits = alloca (nbytes); for (i = 0; i < nbytes; i++) bits[i] = XBM_BIT_SHUFFLE (invertedBits[i]); } @@ -3422,7 +3420,7 @@ xpm_load (struct frame *f, struct image *img) /* Allocate an XpmColorSymbol array. */ size = attrs.numsymbols * sizeof *xpm_syms; - xpm_syms = (XpmColorSymbol *) alloca (size); + xpm_syms = alloca (size); memset (xpm_syms, 0, size); attrs.colorsymbols = xpm_syms; @@ -3445,14 +3443,14 @@ xpm_load (struct frame *f, struct image *img) color = XCDR (XCAR (tail)); if (STRINGP (name)) { - xpm_syms[i].name = (char *) alloca (SCHARS (name) + 1); + xpm_syms[i].name = alloca (SCHARS (name) + 1); strcpy (xpm_syms[i].name, SSDATA (name)); } else xpm_syms[i].name = empty_string; if (STRINGP (color)) { - xpm_syms[i].value = (char *) alloca (SCHARS (color) + 1); + xpm_syms[i].value = alloca (SCHARS (color) + 1); strcpy (xpm_syms[i].value, SSDATA (color)); } else @@ -6449,8 +6447,7 @@ jpeg_load (struct frame *f, struct image *img) a default color, and we don't have to care about which colors can be freed safely, and which can't. */ init_color_table (); - colors = (unsigned long *) alloca (cinfo.actual_number_of_colors - * sizeof *colors); + colors = alloca (cinfo.actual_number_of_colors * sizeof *colors); for (i = 0; i < cinfo.actual_number_of_colors; ++i) { diff --git a/src/keyboard.c b/src/keyboard.c index 0d686e299c5..93f073986f2 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -480,7 +480,7 @@ echo_char (Lisp_Object c) if (current_kboard->immediate_echo) { int size = KEY_DESCRIPTION_SIZE + 100; - char *buffer = (char *) alloca (size); + char *buffer = alloca (size); char *ptr = buffer; Lisp_Object echo_string; @@ -502,7 +502,7 @@ echo_char (Lisp_Object c) { int offset = ptr - buffer; size = max (2 * size, size + nbytes); - buffer = (char *) alloca (size); + buffer = alloca (size); ptr = buffer + offset; } @@ -520,7 +520,7 @@ echo_char (Lisp_Object c) { int offset = ptr - buffer; size += len; - buffer = (char *) alloca (size); + buffer = alloca (size); ptr = buffer + offset; } @@ -884,7 +884,7 @@ static struct kboard_stack *kboard_stack; void push_kboard (struct kboard *k) { - struct kboard_stack *p = xmalloc (sizeof (struct kboard_stack)); + struct kboard_stack *p = xmalloc (sizeof *p); p->next = kboard_stack; p->kboard = current_kboard; @@ -6196,8 +6196,7 @@ apply_modifiers_uncached (int modifiers, char *base, int base_len, int base_len_ /* Since BASE could contain nulls, we can't use intern here; we have to use Fintern, which expects a genuine Lisp_String, and keeps a reference to it. */ - char *new_mods - = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-")); + char new_mods[sizeof "A-C-H-M-S-s-down-drag-double-triple-"]; int mod_len; { @@ -7280,7 +7279,7 @@ add_user_signal (int sig, const char *name) /* Already added. */ return; - p = xmalloc (sizeof (struct user_signal_info)); + p = xmalloc (sizeof *p); p->sig = sig; p->name = xstrdup (name); p->npending = 0; @@ -7506,7 +7505,7 @@ menu_bar_items (Lisp_Object old) Lisp_Object tem; ptrdiff_t nminor; nminor = current_minor_maps (NULL, &tmaps); - maps = (Lisp_Object *) alloca ((nminor + 3) * sizeof (maps[0])); + maps = alloca ((nminor + 3) * sizeof *maps); nmaps = 0; if (tem = get_local_map (PT, current_buffer, Qkeymap), !NILP (tem)) maps[nmaps++] = tem; @@ -8033,7 +8032,7 @@ tool_bar_items (Lisp_Object reuse, int *nitems) if (!NILP (Voverriding_local_map_menu_flag)) { /* Yes, use them (if non-nil) as well as the global map. */ - maps = (Lisp_Object *) alloca (3 * sizeof (maps[0])); + maps = alloca (3 * sizeof *maps); nmaps = 0; if (!NILP (KVAR (current_kboard, Voverriding_terminal_local_map))) maps[nmaps++] = KVAR (current_kboard, Voverriding_terminal_local_map); @@ -8050,7 +8049,7 @@ tool_bar_items (Lisp_Object reuse, int *nitems) Lisp_Object tem; ptrdiff_t nminor; nminor = current_minor_maps (NULL, &tmaps); - maps = (Lisp_Object *) alloca ((nminor + 3) * sizeof (maps[0])); + maps = alloca ((nminor + 3) * sizeof *maps); nmaps = 0; if (tem = get_local_map (PT, current_buffer, Qkeymap), !NILP (tem)) maps[nmaps++] = tem; @@ -8475,8 +8474,7 @@ read_char_x_menu_prompt (ptrdiff_t nmaps, Lisp_Object *maps, && !EQ (XCAR (prev_event), Qtool_bar)) { /* Display the menu and get the selection. */ - Lisp_Object *realmaps - = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); + Lisp_Object *realmaps = alloca (nmaps * sizeof *realmaps); Lisp_Object value; ptrdiff_t nmaps1 = 0; @@ -8570,7 +8568,7 @@ read_char_minibuf_menu_prompt (int commandflag, if (width + 4 > read_char_minibuf_menu_width) { read_char_minibuf_menu_text - = (char *) xrealloc (read_char_minibuf_menu_text, width + 4); + = xrealloc (read_char_minibuf_menu_text, width + 4); read_char_minibuf_menu_width = width + 4; } menu = read_char_minibuf_menu_text; @@ -9177,8 +9175,8 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, { if (2 > nmaps_allocated) { - submaps = (Lisp_Object *) alloca (2 * sizeof (submaps[0])); - defs = (Lisp_Object *) alloca (2 * sizeof (defs[0])); + submaps = alloca (2 * sizeof *submaps); + defs = alloca (2 * sizeof *defs); nmaps_allocated = 2; } submaps[nmaps++] = KVAR (current_kboard, Voverriding_terminal_local_map); @@ -9187,8 +9185,8 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, { if (2 > nmaps_allocated) { - submaps = (Lisp_Object *) alloca (2 * sizeof (submaps[0])); - defs = (Lisp_Object *) alloca (2 * sizeof (defs[0])); + submaps = alloca (2 * sizeof *submaps); + defs = alloca (2 * sizeof *defs); nmaps_allocated = 2; } submaps[nmaps++] = Voverriding_local_map; @@ -9204,8 +9202,8 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, if (total > nmaps_allocated) { - submaps = (Lisp_Object *) alloca (total * sizeof (submaps[0])); - defs = (Lisp_Object *) alloca (total * sizeof (defs[0])); + submaps = alloca (total * sizeof *submaps); + defs = alloca (total * sizeof *defs); nmaps_allocated = total; } @@ -12187,7 +12185,7 @@ variable are `sigusr1' and `sigusr2'. */); Vdebug_on_event = intern_c_string ("sigusr2"); /* Create the initial keyboard. */ - initial_kboard = xmalloc (sizeof (KBOARD)); + initial_kboard = xmalloc (sizeof *initial_kboard); init_kboard (initial_kboard); /* Vwindow_system is left at t for now. */ initial_kboard->next_kboard = all_kboards; diff --git a/src/keymap.c b/src/keymap.c index db4d5d12ee4..234740721ae 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -1478,7 +1478,7 @@ current_minor_maps (Lisp_Object **modeptr, Lisp_Object **mapptr) /* Use malloc here. See the comment above this function. Avoid realloc here; it causes spurious traps on GNU/Linux [KFS] */ BLOCK_INPUT; - newmodes = (Lisp_Object *) malloc (allocsize); + newmodes = malloc (allocsize); if (newmodes) { if (cmm_modes) @@ -1490,7 +1490,7 @@ current_minor_maps (Lisp_Object **modeptr, Lisp_Object **mapptr) cmm_modes = newmodes; } - newmaps = (Lisp_Object *) malloc (allocsize); + newmaps = malloc (allocsize); if (newmaps) { if (cmm_maps) @@ -2923,7 +2923,7 @@ You type Translation\n\ if (!SYMBOLP (modes[i])) abort (); - p = title = (char *) alloca (42 + SCHARS (SYMBOL_NAME (modes[i]))); + p = title = alloca (42 + SCHARS (SYMBOL_NAME (modes[i]))); *p++ = '\f'; *p++ = '\n'; *p++ = '`'; diff --git a/src/lread.c b/src/lread.c index 670831081e8..19783d3102b 100644 --- a/src/lread.c +++ b/src/lread.c @@ -1479,7 +1479,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto this path element/specified file name and any possible suffix. */ want_length = max_suffix_len + SBYTES (filename); if (fn_size <= want_length) - fn = (char *) alloca (fn_size = 100 + want_length); + fn = alloca (fn_size = 100 + want_length); /* Loop over suffixes. */ for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes; @@ -2630,8 +2630,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) } if (nskip > saved_doc_string_size) { - saved_doc_string = (char *) xrealloc (saved_doc_string, - nskip + extra); + saved_doc_string = xrealloc (saved_doc_string, nskip + extra); saved_doc_string_size = nskip + extra; } @@ -2894,8 +2893,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) ptrdiff_t offset = p - read_buffer; if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) memory_full (SIZE_MAX); - read_buffer = (char *) xrealloc (read_buffer, - read_buffer_size * 2); + read_buffer = xrealloc (read_buffer, read_buffer_size * 2); read_buffer_size *= 2; p = read_buffer + offset; end = read_buffer + read_buffer_size; @@ -3029,8 +3027,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) ptrdiff_t offset = p - read_buffer; if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) memory_full (SIZE_MAX); - read_buffer = (char *) xrealloc (read_buffer, - read_buffer_size * 2); + read_buffer = xrealloc (read_buffer, read_buffer_size * 2); read_buffer_size *= 2; p = read_buffer + offset; end = read_buffer + read_buffer_size; @@ -3060,8 +3057,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) ptrdiff_t offset = p - read_buffer; if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) memory_full (SIZE_MAX); - read_buffer = (char *) xrealloc (read_buffer, - read_buffer_size * 2); + read_buffer = xrealloc (read_buffer, read_buffer_size * 2); read_buffer_size *= 2; p = read_buffer + offset; end = read_buffer + read_buffer_size; diff --git a/src/macros.c b/src/macros.c index 7c8bc4c13b8..0b1eda0b8ab 100644 --- a/src/macros.c +++ b/src/macros.c @@ -63,8 +63,7 @@ macro before appending to it. */) if (!current_kboard->kbd_macro_buffer) { - current_kboard->kbd_macro_buffer - = (Lisp_Object *)xmalloc (30 * sizeof (Lisp_Object)); + current_kboard->kbd_macro_buffer = xmalloc (30 * sizeof (Lisp_Object)); current_kboard->kbd_macro_bufsize = 30; } update_mode_lines++; @@ -205,8 +204,7 @@ store_kbd_macro_char (Lisp_Object c) < kb->kbd_macro_bufsize) memory_full (SIZE_MAX); nbytes = kb->kbd_macro_bufsize * (2 * sizeof *kb->kbd_macro_buffer); - kb->kbd_macro_buffer - = (Lisp_Object *) xrealloc (kb->kbd_macro_buffer, nbytes); + kb->kbd_macro_buffer = xrealloc (kb->kbd_macro_buffer, nbytes); kb->kbd_macro_bufsize *= 2; kb->kbd_macro_ptr = kb->kbd_macro_buffer + ptr_offset; kb->kbd_macro_end = kb->kbd_macro_buffer + end_offset; diff --git a/src/menu.c b/src/menu.c index 598385c38c0..3b8ebb65d2c 100644 --- a/src/menu.c +++ b/src/menu.c @@ -632,8 +632,7 @@ digest_single_submenu (int start, int end, int top_level_items) widget_value **submenu_stack; int panes_seen = 0; - submenu_stack - = (widget_value **) alloca (menu_items_used * sizeof (widget_value *)); + submenu_stack = alloca (menu_items_used * sizeof *submenu_stack); wv = xmalloc_widget_value (); wv->name = "menu"; wv->value = 0; @@ -893,7 +892,7 @@ find_and_call_menu_selection (FRAME_PTR f, int menu_bar_items_used, Lisp_Object int i; entry = Qnil; - subprefix_stack = (Lisp_Object *) alloca (menu_bar_items_used * sizeof (Lisp_Object)); + subprefix_stack = alloca (menu_bar_items_used * sizeof *subprefix_stack); prefix = Qnil; i = 0; diff --git a/src/nsfns.m b/src/nsfns.m index cd943ac4bab..5303a5ec313 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -1203,8 +1203,7 @@ This function is an internal primitive--use `make-frame' instead. */) f->terminal = dpyinfo->terminal; f->output_method = output_ns; - f->output_data.ns = (struct ns_output *)xmalloc (sizeof *(f->output_data.ns)); - memset (f->output_data.ns, 0, sizeof *(f->output_data.ns)); + f->output_data.ns = xzalloc (sizeof *f->output_data.ns); FRAME_FONTSET (f) = -1; diff --git a/src/nsfont.m b/src/nsfont.m index 556102b6f44..7a456c4bb5d 100644 --- a/src/nsfont.m +++ b/src/nsfont.m @@ -152,7 +152,7 @@ ns_spec_to_descriptor (Lisp_Object font_spec) [fdAttrs setObject: tdict forKey: NSFontTraitsAttribute]; fdesc = [NSFontDescriptor fontDescriptorWithFontAttributes: fdAttrs]; - if (family != nil) + if (family != nil) { fdesc = [fdesc fontDescriptorWithFamily: family]; } @@ -779,14 +779,8 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size) if (!font) return Qnil; /* FIXME: other terms do, but return Qnil causes segfault */ - font_info->glyphs = (unsigned short **) - xmalloc (0x100 * sizeof (unsigned short *)); - font_info->metrics = (struct font_metrics **) - xmalloc (0x100 * sizeof (struct font_metrics *)); - if (!font_info->glyphs || !font_info->metrics) - return Qnil; - memset (font_info->glyphs, 0, 0x100 * sizeof (unsigned short *)); - memset (font_info->metrics, 0, 0x100 * sizeof (struct font_metrics *)); + font_info->glyphs = xzalloc (0x100 * sizeof *font_info->glyphs); + font_info->metrics = xzalloc (0x100 * sizeof *font_info->metrics); BLOCK_INPUT; @@ -831,8 +825,7 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size) [font_info->nsfont retain]; /* set up ns_font (defined in nsgui.h) */ - font_info->name = (char *)xmalloc (strlen (fontName)+1); - strcpy (font_info->name, fontName); + font_info->name = xstrdup (fontName); font_info->bold = [fontMgr traitsOfFont: nsfont] & NSBoldFontMask; font_info->ital = synthItal || ([fontMgr traitsOfFont: nsfont] & NSItalicFontMask); @@ -1371,8 +1364,7 @@ ns_glyph_metrics (struct nsfont_info *font_info, unsigned char block) BLOCK_INPUT; sfont = [font_info->nsfont screenFont]; - font_info->metrics[block] = xmalloc (0x100 * sizeof (struct font_metrics)); - memset (font_info->metrics[block], 0, 0x100 * sizeof (struct font_metrics)); + font_info->metrics[block] = xzalloc (0x100 * sizeof (struct font_metrics)); if (!(font_info->metrics[block])) abort (); @@ -1417,7 +1409,7 @@ ns_glyph_metrics (struct nsfont_info *font_info, unsigned char block) maxChar = 0; maxGlyph = 0; dict = [NSMutableDictionary new]; - cglyphs = (CGGlyph *)xmalloc (c * sizeof (CGGlyph)); + cglyphs = xmalloc (c * sizeof (CGGlyph)); return self; } diff --git a/src/nsmenu.m b/src/nsmenu.m index 9d74337580a..cccecffb427 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -190,8 +190,7 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu) ptrdiff_t specpdl_count = SPECPDL_INDEX (); int previous_menu_items_used = f->menu_bar_items_used; Lisp_Object *previous_items - = (Lisp_Object *) alloca (previous_menu_items_used - * sizeof (Lisp_Object)); + = alloca (previous_menu_items_used * sizeof *previous_items); /* lisp preliminaries */ buffer = XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer; @@ -231,11 +230,11 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu) menu_items = f->menu_bar_vector; menu_items_allocated = VECTORP (menu_items) ? ASIZE (menu_items) : 0; - submenu_start = (int *) alloca (ASIZE (items) * sizeof (int *)); - submenu_end = (int *) alloca (ASIZE (items) * sizeof (int *)); - submenu_n_panes = (int *) alloca (ASIZE (items) * sizeof (int)); - submenu_top_level_items - = (int *) alloca (ASIZE (items) * sizeof (int *)); + submenu_start = alloca (ASIZE (items) * sizeof *submenu_start); + submenu_end = alloca (ASIZE (items) * sizeof *submenu_end); + submenu_n_panes = alloca (ASIZE (items) * sizeof *submenu_n_panes); + submenu_top_level_items = alloca (ASIZE (items) + * sizeof *submenu_top_level_items); init_menu_items (); for (i = 0; i < ASIZE (items); i += 4) { @@ -814,9 +813,9 @@ ns_menu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, { widget_value *save_wv = 0, *prev_wv = 0; widget_value **submenu_stack - = (widget_value **) alloca (menu_items_used * sizeof (widget_value *)); + = alloca (menu_items_used * sizeof *submenu_stack); /* Lisp_Object *subprefix_stack - = (Lisp_Object *) alloca (menu_items_used * sizeof (Lisp_Object)); */ + = alloca (menu_items_used * sizeof *subprefix_stack); */ int submenu_depth = 0; int first_pane = 1; int i; diff --git a/src/nsterm.m b/src/nsterm.m index 431577c4f01..ae536638c33 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -1323,8 +1323,7 @@ ns_index_color (NSColor *color, struct frame *f) { color_table->size = NS_COLOR_CAPACITY; color_table->avail = 1; /* skip idx=0 as marker */ - color_table->colors - = (NSColor **)xmalloc (color_table->size * sizeof (NSColor *)); + color_table->colors = xmalloc (color_table->size * sizeof (NSColor *)); color_table->colors[0] = nil; color_table->empty_indices = [[NSMutableSet alloc] init]; } @@ -2245,17 +2244,9 @@ ns_draw_fringe_bitmap (struct window *w, struct glyph_row *row, /* grow bimgs if needed */ if (nBimgs < max_used_fringe_bitmap) { - EmacsImage **newBimgs - = xmalloc (max_used_fringe_bitmap * sizeof (EmacsImage *)); - memset (newBimgs, 0, max_used_fringe_bitmap * sizeof (EmacsImage *)); - - if (nBimgs) - { - memcpy (newBimgs, bimgs, nBimgs * sizeof (EmacsImage *)); - xfree (bimgs); - } - - bimgs = newBimgs; + bimgs = xrealloc (bimgs, max_used_fringe_bitmap * sizeof *bimgs); + memset (bimgs + nBimgs, 0, + (max_used_fringe_bitmap - nBimgs) * sizeof *bimgs); nBimgs = max_used_fringe_bitmap; } @@ -3889,8 +3880,7 @@ ns_initialize_display_info (struct ns_display_info *dpyinfo) NSColorSpaceFromDepth (depth)]; dpyinfo->n_planes = NSBitsPerPixelFromDepth (depth); dpyinfo->image_cache = make_image_cache (); - dpyinfo->color_table - = (struct ns_color_table *)xmalloc (sizeof (struct ns_color_table)); + dpyinfo->color_table = xmalloc (sizeof *dpyinfo->color_table); dpyinfo->color_table->colors = NULL; dpyinfo->root_window = 42; /* a placeholder.. */ @@ -4071,13 +4061,12 @@ ns_term_init (Lisp_Object display_name) selector: @selector (logNotification:) name: nil object: nil]; */ - dpyinfo = (struct ns_display_info *)xmalloc (sizeof (struct ns_display_info)); - memset (dpyinfo, 0, sizeof (struct ns_display_info)); + dpyinfo = xzalloc (sizeof *dpyinfo); ns_initialize_display_info (dpyinfo); terminal = ns_create_terminal (dpyinfo); - terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); + terminal->kboard = xmalloc (sizeof *terminal->kboard); init_kboard (terminal->kboard); KVAR (terminal->kboard, Vwindow_system) = Qns; terminal->kboard->next_kboard = all_kboards; @@ -4098,7 +4087,7 @@ ns_term_init (Lisp_Object display_name) dpyinfo->name_list_element = XCAR (ns_display_name_list); /* Set the name of the terminal. */ - terminal->name = (char *) xmalloc (SBYTES (display_name) + 1); + terminal->name = xmalloc (SBYTES (display_name) + 1); strncpy (terminal->name, SDATA (display_name), SBYTES (display_name)); terminal->name[SBYTES (display_name)] = 0; @@ -5355,8 +5344,7 @@ ns_term_shutdown (int sig) char *pos = strstr (t, " — "); if (pos) *pos = '\0'; - old_title = (char *) xmalloc (strlen (t) + 1); - strcpy (old_title, t); + old_title = xstrdup (t); } size_title = xmalloc (strlen (old_title) + 40); esprintf (size_title, "%s — (%d x %d)", old_title, cols, rows); @@ -6076,7 +6064,7 @@ ns_term_shutdown (int sig) if (nr_screens == 1) return [super constrainFrameRect:frameRect toScreen:screen]; - + if (f->output_data.ns->dont_constrain || ns_menu_bar_should_be_hidden ()) return frameRect; diff --git a/src/print.c b/src/print.c index b0189b9bc20..b650b1265b1 100644 --- a/src/print.c +++ b/src/print.c @@ -173,8 +173,7 @@ int print_output_debug_flag EXTERNALLY_VISIBLE = 1; if (print_buffer_pos != print_buffer_pos_byte \ && NILP (BVAR (current_buffer, enable_multibyte_characters))) \ { \ - unsigned char *temp \ - = (unsigned char *) alloca (print_buffer_pos + 1); \ + unsigned char *temp = alloca (print_buffer_pos + 1); \ copy_text ((unsigned char *) print_buffer, temp, \ print_buffer_pos_byte, 1, 0); \ insert_1_both ((char *) temp, print_buffer_pos, \ diff --git a/src/process.c b/src/process.c index 3f329872c76..2cb9e8de15f 100644 --- a/src/process.c +++ b/src/process.c @@ -1365,7 +1365,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) val = Vcoding_system_for_read; if (NILP (val)) { - args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2); + args2 = alloca ((nargs + 1) * sizeof *args2); args2[0] = Qstart_process; for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; GCPRO2 (proc, current_dir); @@ -1384,7 +1384,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) { if (EQ (coding_systems, Qt)) { - args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2); + args2 = alloca ((nargs + 1) * sizeof *args2); args2[0] = Qstart_process; for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; GCPRO2 (proc, current_dir); @@ -1478,7 +1478,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) /* Now that everything is encoded we can collect the strings into NEW_ARGV. */ - new_argv = (unsigned char **) alloca ((nargs - 1) * sizeof (char *)); + new_argv = alloca ((nargs - 1) * sizeof *new_argv); new_argv[nargs - 2] = 0; for (i = nargs - 2; i-- != 0; ) @@ -5037,7 +5037,7 @@ read_process_output (Lisp_Object proc, register int channel) ptrdiff_t count = SPECPDL_INDEX (); Lisp_Object odeactivate; - chars = (char *) alloca (carryover + readmax); + chars = alloca (carryover + readmax); if (carryover) /* See the comment above. */ memcpy (chars, SDATA (p->decoding_buf), carryover); @@ -7083,8 +7083,7 @@ setup_process_coding_systems (Lisp_Object process) return; if (!proc_decode_coding_system[inch]) - proc_decode_coding_system[inch] - = xmalloc (sizeof (struct coding_system)); + proc_decode_coding_system[inch] = xmalloc (sizeof (struct coding_system)); coding_system = p->decode_coding_system; if (! NILP (p->filter)) ; @@ -7096,8 +7095,7 @@ setup_process_coding_systems (Lisp_Object process) setup_coding_system (coding_system, proc_decode_coding_system[inch]); if (!proc_encode_coding_system[outch]) - proc_encode_coding_system[outch] - = xmalloc (sizeof (struct coding_system)); + proc_encode_coding_system[outch] = xmalloc (sizeof (struct coding_system)); setup_coding_system (p->encode_coding_system, proc_encode_coding_system[outch]); #endif diff --git a/src/ralloc.c b/src/ralloc.c index 0d8bcaf4ffb..c40258693f5 100644 --- a/src/ralloc.c +++ b/src/ralloc.c @@ -396,7 +396,7 @@ get_bloc (SIZE size) register bloc_ptr new_bloc; register heap_ptr heap; - if (! (new_bloc = (bloc_ptr) malloc (BLOC_PTR_SIZE)) + if (! (new_bloc = malloc (BLOC_PTR_SIZE)) || ! (new_bloc->data = obtain (break_value, size))) { free (new_bloc); 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; diff --git a/src/region-cache.c b/src/region-cache.c index a3a2a072c8c..14b6233a5a5 100644 --- a/src/region-cache.c +++ b/src/region-cache.c @@ -132,7 +132,7 @@ static void revalidate_region_cache (struct buffer *buf, struct region_cache *c) struct region_cache * new_region_cache (void) { - struct region_cache *c = xmalloc (sizeof (struct region_cache)); + struct region_cache *c = xmalloc (sizeof *c); c->gap_start = 0; c->gap_len = NEW_CACHE_GAP; diff --git a/src/scroll.c b/src/scroll.c index 86d775545b0..78ebe65bdcc 100644 --- a/src/scroll.c +++ b/src/scroll.c @@ -253,11 +253,11 @@ do_scrolling (struct frame *frame, struct glyph_matrix *current_matrix, /* A queue for line insertions to be done. */ struct queue { int count, pos; }; struct queue *queue_start - = (struct queue *) alloca (current_matrix->nrows * sizeof (struct queue)); + = alloca (current_matrix->nrows * sizeof *queue_start); struct queue *queue = queue_start; - char *retained_p = (char *) alloca (window_size * sizeof (char)); - int *copy_from = (int *) alloca (window_size * sizeof (int)); + char *retained_p = alloca (window_size * sizeof *retained_p); + int *copy_from = alloca (window_size * sizeof *copy_from); /* Zero means line is empty. */ memset (retained_p, 0, window_size * sizeof (char)); @@ -671,11 +671,11 @@ do_direct_scrolling (struct frame *frame, struct glyph_matrix *current_matrix, int write_follows_p = 1; /* For each row in the new matrix what row of the old matrix it is. */ - int *copy_from = (int *) alloca (window_size * sizeof (int)); + int *copy_from = alloca (window_size * sizeof *copy_from); /* Non-zero for each row in the new matrix that is retained from the old matrix. Lines not retained are empty. */ - char *retained_p = (char *) alloca (window_size * sizeof (char)); + char *retained_p = alloca (window_size * sizeof *retained_p); memset (retained_p, 0, window_size * sizeof (char)); diff --git a/src/search.c b/src/search.c index a7ea3634579..9004dc78271 100644 --- a/src/search.c +++ b/src/search.c @@ -175,8 +175,7 @@ shrink_regexp_cache (void) for (cp = searchbuf_head; cp != 0; cp = cp->next) { cp->buf.allocated = cp->buf.used; - cp->buf.buffer - = (unsigned char *) xrealloc (cp->buf.buffer, cp->buf.used); + cp->buf.buffer = xrealloc (cp->buf.buffer, cp->buf.used); } } @@ -1274,7 +1273,7 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, raw_pattern_size_byte = count_size_as_multibyte (SDATA (string), raw_pattern_size); - raw_pattern = (unsigned char *) alloca (raw_pattern_size_byte + 1); + raw_pattern = alloca (raw_pattern_size_byte + 1); copy_text (SDATA (string), raw_pattern, SCHARS (string), 0, 1); } @@ -1288,7 +1287,7 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, the chosen single-byte character set can possibly match. */ raw_pattern_size = SCHARS (string); raw_pattern_size_byte = SCHARS (string); - raw_pattern = (unsigned char *) alloca (raw_pattern_size + 1); + raw_pattern = alloca (raw_pattern_size + 1); copy_text (SDATA (string), raw_pattern, SBYTES (string), 1, 0); } @@ -1296,7 +1295,7 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, /* Copy and optionally translate the pattern. */ len = raw_pattern_size; len_byte = raw_pattern_size_byte; - patbuf = (unsigned char *) alloca (len * MAX_MULTIBYTE_LENGTH); + patbuf = alloca (len * MAX_MULTIBYTE_LENGTH); pat = patbuf; base_pat = raw_pattern; if (multibyte) @@ -2741,8 +2740,7 @@ Return value is undefined if the last search failed. */) prev = Qnil; - data = (Lisp_Object *) alloca ((2 * search_regs.num_regs + 1) - * sizeof (Lisp_Object)); + data = alloca ((2 * search_regs.num_regs + 1) * sizeof *data); len = 0; for (i = 0; i < search_regs.num_regs; i++) @@ -3008,7 +3006,7 @@ DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0, CHECK_STRING (string); - temp = (char *) alloca (SBYTES (string) * 2); + temp = alloca (SBYTES (string) * 2); /* Now copy the data into the new string, inserting escapes. */ diff --git a/src/sound.c b/src/sound.c index e28e8c69f11..adeb3c47f0f 100644 --- a/src/sound.c +++ b/src/sound.c @@ -594,7 +594,7 @@ wav_play (struct sound *s, struct sound_device *sd) ptrdiff_t blksize = sd->period_size ? sd->period_size (sd) : 2048; ptrdiff_t data_left = header->data_length; - buffer = (char *) alloca (blksize); + buffer = alloca (blksize); lseek (s->fd, sizeof *header, SEEK_SET); while (data_left > 0 && (nbytes = emacs_read (s->fd, buffer, blksize)) > 0) @@ -688,7 +688,7 @@ au_play (struct sound *s, struct sound_device *sd) lseek (s->fd, header->data_offset, SEEK_SET); /* Copy sound data to the device. */ - buffer = (char *) alloca (blksize); + buffer = alloca (blksize); while ((nbytes = emacs_read (s->fd, buffer, blksize)) > 0) sd->write (sd, buffer, nbytes); @@ -932,7 +932,7 @@ alsa_open (struct sound_device *sd) else file = DEFAULT_ALSA_SOUND_DEVICE; - p = xmalloc (sizeof (*p)); + p = xmalloc (sizeof *p); p->handle = NULL; p->hwparams = NULL; p->swparams = NULL; @@ -1364,10 +1364,10 @@ Internal use only, use `play-sound' instead. */) #ifndef WINDOWSNT file = Qnil; GCPRO2 (sound, file); - current_sound_device = xzalloc (sizeof (struct sound_device)); - current_sound = xzalloc (sizeof (struct sound)); + current_sound_device = xzalloc (sizeof *current_sound_device); + current_sound = xzalloc (sizeof *current_sound); record_unwind_protect (sound_cleanup, Qnil); - current_sound->header = (char *) alloca (MAX_SOUND_HEADER_BYTES); + current_sound->header = alloca (MAX_SOUND_HEADER_BYTES); if (STRINGP (attrs[SOUND_FILE])) { @@ -1399,7 +1399,7 @@ Internal use only, use `play-sound' instead. */) if (STRINGP (attrs[SOUND_DEVICE])) { int len = SCHARS (attrs[SOUND_DEVICE]); - current_sound_device->file = (char *) alloca (len + 1); + current_sound_device->file = alloca (len + 1); strcpy (current_sound_device->file, SSDATA (attrs[SOUND_DEVICE])); } @@ -1431,7 +1431,7 @@ Internal use only, use `play-sound' instead. */) lo_file = Fexpand_file_name (attrs[SOUND_FILE], Qnil); len = XSTRING (lo_file)->size; - psz_file = (char *) alloca (len + 1); + psz_file = alloca (len + 1); strcpy (psz_file, XSTRING (lo_file)->data); if (INTEGERP (attrs[SOUND_VOLUME])) { diff --git a/src/syntax.c b/src/syntax.c index e7e68e23744..de1ab2a7516 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -1581,7 +1581,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl fastmap[CHAR_LEADING_CODE (c)] = 1; range_start_byte = i; range_start_char = c; - char_ranges = (int *) alloca (sizeof (int) * 128 * 2); + char_ranges = alloca (sizeof *char_ranges * 128 * 2); for (i = 129; i < 0400; i++) { c = BYTE8_TO_CHAR (i); @@ -1602,7 +1602,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl } else /* STRING is multibyte */ { - char_ranges = (int *) alloca (sizeof (int) * SCHARS (string) * 2); + char_ranges = alloca (sizeof *char_ranges * SCHARS (string) * 2); while (i_byte < size_byte) { diff --git a/src/sysdep.c b/src/sysdep.c index afab85439f3..7a4fa9aa5f7 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -143,7 +143,7 @@ get_current_dir_name (void) #endif ) { - buf = (char *) malloc (strlen (pwd) + 1); + buf = malloc (strlen (pwd) + 1); if (!buf) return NULL; strcpy (buf, pwd); @@ -152,7 +152,7 @@ get_current_dir_name (void) else { size_t buf_size = 1024; - buf = (char *) malloc (buf_size); + buf = malloc (buf_size); if (!buf) return NULL; for (;;) @@ -167,7 +167,7 @@ get_current_dir_name (void) return NULL; } buf_size *= 2; - buf = (char *) realloc (buf, buf_size); + buf = realloc (buf, buf_size); if (!buf) return NULL; } @@ -176,7 +176,7 @@ get_current_dir_name (void) else { /* We need MAXPATHLEN here. */ - buf = (char *) malloc (MAXPATHLEN + 1); + buf = malloc (MAXPATHLEN + 1); if (!buf) return NULL; if (getwd (buf) == NULL) @@ -516,7 +516,7 @@ sys_subshell (void) goto xyzzy; dir = expand_and_dir_to_file (Funhandled_file_name_directory (dir), Qnil); - str_volatile = str = (unsigned char *) alloca (SCHARS (dir) + 2); + str_volatile = str = alloca (SCHARS (dir) + 2); len = SCHARS (dir); memcpy (str, SDATA (dir), len); if (str[len - 1] != '/') str[len++] = '/'; @@ -851,7 +851,7 @@ init_sys_modes (struct tty_display_info *tty_out) return; /* The tty is suspended. */ if (! tty_out->old_tty) - tty_out->old_tty = xmalloc (sizeof (struct emacs_tty)); + tty_out->old_tty = xmalloc (sizeof *tty_out->old_tty); emacs_get_tty (fileno (tty_out->input), tty_out->old_tty); @@ -1345,7 +1345,7 @@ init_system_name (void) Vsystem_name = build_string (uts.nodename); #else /* HAVE_GETHOSTNAME */ unsigned int hostname_size = 256; - char *hostname = (char *) alloca (hostname_size); + char *hostname = alloca (hostname_size); /* Try to get the host name; if the buffer is too short, try again. Apparently, the only indication gethostname gives of @@ -1361,7 +1361,7 @@ init_system_name (void) break; hostname_size <<= 1; - hostname = (char *) alloca (hostname_size); + hostname = alloca (hostname_size); } #ifdef HAVE_SOCKETS /* Turn the hostname into the official, fully-qualified hostname. diff --git a/src/term.c b/src/term.c index ebf2f0b341e..5e48cbbfc64 100644 --- a/src/term.c +++ b/src/term.c @@ -2858,13 +2858,11 @@ DEFUN ("gpm-mouse-stop", Fgpm_mouse_stop, Sgpm_mouse_stop, void create_tty_output (struct frame *f) { - struct tty_output *t; + struct tty_output *t = xzalloc (sizeof *t); if (! FRAME_TERMCAP_P (f)) abort (); - t = xzalloc (sizeof (struct tty_output)); - t->display_info = FRAME_TERMINAL (f)->display_info.tty; f->output_data.tty = t; @@ -3064,7 +3062,7 @@ init_tty (const char *name, const char *terminal_type, int must_succeed) been_here = 1; tty = &the_only_display_info; #else - tty = xzalloc (sizeof (struct tty_display_info)); + tty = xzalloc (sizeof *tty); #endif tty->next = tty_list; tty_list = tty; @@ -3073,7 +3071,7 @@ init_tty (const char *name, const char *terminal_type, int must_succeed) terminal->display_info.tty = tty; tty->terminal = terminal; - tty->Wcm = xmalloc (sizeof (struct cm)); + tty->Wcm = xmalloc (sizeof *tty->Wcm); Wcm_clear (tty); encode_terminal_src_size = 0; @@ -3343,7 +3341,7 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ tty->mouse_highlight.mouse_face_window = Qnil; #endif - terminal->kboard = xmalloc (sizeof (KBOARD)); + terminal->kboard = xmalloc (sizeof *terminal->kboard); init_kboard (terminal->kboard); KVAR (terminal->kboard, Vwindow_system) = Qnil; terminal->kboard->next_kboard = all_kboards; diff --git a/src/termcap.c b/src/termcap.c index ea096d789da..d1b05e8df94 100644 --- a/src/termcap.c +++ b/src/termcap.c @@ -478,7 +478,7 @@ tgetent (char *bp, const char *name) { ptrdiff_t offset1 = bp1 - bp, offset2 = tc_search_point - bp; malloc_size = offset1 + buf.size; - bp = termcap_name = (char *) xrealloc (bp, malloc_size); + bp = termcap_name = xrealloc (bp, malloc_size); bp1 = termcap_name + offset1; tc_search_point = termcap_name + offset2; } @@ -504,7 +504,7 @@ tgetent (char *bp, const char *name) xfree (buf.beg); if (malloc_size) - bp = (char *) xrealloc (bp, bp1 - bp + 1); + bp = xrealloc (bp, bp1 - bp + 1); ret: term_entry = bp; diff --git a/src/unexmacosx.c b/src/unexmacosx.c index 423853c8139..0f5ad5498b0 100644 --- a/src/unexmacosx.c +++ b/src/unexmacosx.c @@ -394,7 +394,7 @@ build_region_list (void) } else { - r = (struct region_t *) malloc (sizeof (struct region_t)); + r = malloc (sizeof *r); if (!r) unexec_error ("cannot allocate region structure"); @@ -669,7 +669,7 @@ read_load_commands (void) #endif nlc = mh.ncmds; - lca = (struct load_command **) malloc (nlc * sizeof (struct load_command *)); + lca = malloc (nlc * sizeof *lca); for (i = 0; i < nlc; i++) { @@ -678,7 +678,7 @@ read_load_commands (void) size first and then read the rest. */ if (!unexec_read (&lc, sizeof (struct load_command))) unexec_error ("cannot read load command"); - lca[i] = (struct load_command *) malloc (lc.cmdsize); + lca[i] = malloc (lc.cmdsize); memcpy (lca[i], &lc, sizeof (struct load_command)); if (!unexec_read (lca[i] + 1, lc.cmdsize - sizeof (struct load_command))) unexec_error ("cannot read content of load command"); @@ -1378,7 +1378,7 @@ unexec_realloc (void *old_ptr, size_t new_size) size_t old_size = ((unexec_malloc_header_t *) old_ptr)[-1].u.size; size_t size = new_size > old_size ? old_size : new_size; - p = (size_t *) malloc (new_size); + p = malloc (new_size); if (size) memcpy (p, old_ptr, size); } diff --git a/src/window.c b/src/window.c index 229035fe81e..0f88cbaece9 100644 --- a/src/window.c +++ b/src/window.c @@ -5469,9 +5469,8 @@ the return value is nil. Otherwise the value is t. */) really like to do is to free only those matrices not reused below. */ root_window = XWINDOW (FRAME_ROOT_WINDOW (f)); - leaf_windows - = (struct window **) alloca (count_windows (root_window) - * sizeof (struct window *)); + leaf_windows = alloca (count_windows (root_window) + * sizeof *leaf_windows); n_leaf_windows = get_leaf_windows (root_window, leaf_windows, 0); /* Kludge Alert! diff --git a/src/xdisp.c b/src/xdisp.c index 0c210198fc5..0684a68444e 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -5400,8 +5400,7 @@ load_overlay_strings (struct it *it, ptrdiff_t charpos) ptrdiff_t size = 20; ptrdiff_t n = 0, i, j; int invis_p; - struct overlay_entry *entries - = (struct overlay_entry *) alloca (size * sizeof *entries); + struct overlay_entry *entries = alloca (size * sizeof *entries); USE_SAFE_ALLOCA; if (charpos <= 0) @@ -14949,7 +14948,7 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, int *scroll_ste return rc; #endif - /* Previously, there was a check for Lisp integer in the + /* Previously, there was a check for Lisp integer in the if-statement below. Now, this field is converted to ptrdiff_t, thus zero means invalid position in a buffer. */ eassert (w->last_point > 0); @@ -18012,7 +18011,7 @@ dump_glyph_row (struct glyph_row *row, int vpos, int glyphs) for (area = LEFT_MARGIN_AREA; area < LAST_AREA; ++area) { - char *s = (char *) alloca (row->used[area] + 1); + char *s = alloca (row->used[area] + 1); int i; for (i = 0; i < row->used[area]; ++i) @@ -21137,7 +21136,7 @@ decode_mode_spec_coding (Lisp_Object coding_system, register char *buf, int eol_ } else if (CHARACTERP (eoltype)) { - unsigned char *tmp = (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH); + unsigned char *tmp = alloca (MAX_MULTIBYTE_LENGTH); int c = XFASTINT (eoltype); eol_str_len = CHAR_STRING (c, tmp); eol_str = tmp; @@ -23010,7 +23009,7 @@ compute_overhangs_and_x (struct glyph_string *s, int x, int backward_p) #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \ do \ { \ - s = (struct glyph_string *) alloca (sizeof *s); \ + s = alloca (sizeof *s); \ INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \ START = fill_stretch_glyph_string (s, START, END); \ append_glyph_string (&HEAD, &TAIL, s); \ @@ -23030,7 +23029,7 @@ compute_overhangs_and_x (struct glyph_string *s, int x, int backward_p) #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \ do \ { \ - s = (struct glyph_string *) alloca (sizeof *s); \ + s = alloca (sizeof *s); \ INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \ fill_image_glyph_string (s); \ append_glyph_string (&HEAD, &TAIL, s); \ @@ -23057,8 +23056,8 @@ compute_overhangs_and_x (struct glyph_string *s, int x, int backward_p) \ face_id = (row)->glyphs[area][START].face_id; \ \ - s = (struct glyph_string *) alloca (sizeof *s); \ - char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \ + s = alloca (sizeof *s); \ + char2b = alloca ((END - START) * sizeof *char2b); \ INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \ append_glyph_string (&HEAD, &TAIL, s); \ s->x = (X); \ @@ -23086,13 +23085,13 @@ compute_overhangs_and_x (struct glyph_string *s, int x, int backward_p) struct glyph_string *first_s = NULL; \ int n; \ \ - char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \ + char2b = alloca (cmp->glyph_len * sizeof *char2b); \ \ /* Make glyph_strings for each glyph sequence that is drawable by \ the same face, and append them to HEAD/TAIL. */ \ for (n = 0; n < cmp->glyph_len;) \ { \ - s = (struct glyph_string *) alloca (sizeof *s); \ + s = alloca (sizeof *s); \ INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \ append_glyph_string (&(HEAD), &(TAIL), s); \ s->cmp = cmp; \ @@ -23120,9 +23119,8 @@ compute_overhangs_and_x (struct glyph_string *s, int x, int backward_p) face_id = (row)->glyphs[area][START].face_id; \ gstring = (composition_gstring_from_id \ ((row)->glyphs[area][START].u.cmp.id)); \ - s = (struct glyph_string *) alloca (sizeof *s); \ - char2b = (XChar2b *) alloca ((sizeof *char2b) \ - * LGSTRING_GLYPH_LEN (gstring)); \ + s = alloca (sizeof *s); \ + char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \ INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \ append_glyph_string (&(HEAD), &(TAIL), s); \ s->x = (X); \ @@ -23141,7 +23139,7 @@ compute_overhangs_and_x (struct glyph_string *s, int x, int backward_p) \ face_id = (row)->glyphs[area][START].face_id; \ \ - s = (struct glyph_string *) alloca (sizeof *s); \ + s = alloca (sizeof *s); \ INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \ append_glyph_string (&HEAD, &TAIL, s); \ s->x = (X); \ diff --git a/src/xfaces.c b/src/xfaces.c index 28ef5e6cd13..a1062a44232 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -703,9 +703,8 @@ x_create_gc (struct frame *f, unsigned long mask, XGCValues *xgcv) { - GC gc = xmalloc (sizeof (*gc)); - if (gc) - memcpy (gc, xgcv, sizeof (XGCValues)); + GC gc = xmalloc (sizeof *gc); + memcpy (gc, xgcv, sizeof (XGCValues)); return gc; } @@ -2951,7 +2950,7 @@ FRAME 0 means change the face on all frames, and change the default else if (EQ (attr, QCunderline)) { int valid_p = 0; - + if (UNSPECIFIEDP (value) || IGNORE_DEFFACE_P (value)) valid_p = 1; else if (NILP (value) || EQ (value, Qt)) @@ -2971,8 +2970,8 @@ FRAME 0 means change the face on all frames, and change the default list = CDR_SAFE (list); val = CAR_SAFE (list); list = CDR_SAFE (list); - - if(NILP (key) || NILP (val)) + + if (NILP (key) || NILP (val)) { valid_p = 0; break; @@ -2985,8 +2984,8 @@ FRAME 0 means change the face on all frames, and change the default valid_p = 0; break; } - - else if (EQ (key, QCstyle) + + else if (EQ (key, QCstyle) && !(EQ (val, Qline) || EQ (val, Qwave))) { valid_p = 0; @@ -2994,10 +2993,10 @@ FRAME 0 means change the face on all frames, and change the default } } } - + if (!valid_p) signal_error ("Invalid face underline", value); - + old_value = LFACE_UNDERLINE (lface); LFACE_UNDERLINE (lface) = value; } @@ -5774,7 +5773,7 @@ realize_x_face (struct face_cache *cache, Lisp_Object *attrs) } else if (CONSP (underline)) { - /* `(:color COLOR :style STYLE)'. + /* `(:color COLOR :style STYLE)'. STYLE being one of `line' or `wave'. */ face->underline_p = 1; face->underline_color = 0; @@ -5816,7 +5815,7 @@ realize_x_face (struct face_cache *cache, Lisp_Object *attrs) } } } - + overline = attrs[LFACE_OVERLINE_INDEX]; if (STRINGP (overline)) { diff --git a/src/xfns.c b/src/xfns.c index e90f3099f21..ec729fab566 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -1881,7 +1881,7 @@ xic_create_fontsetname (const char *base_fontname, int motif) /* Make a fontset name from the base font name. */ if (xic_default_fontset == base_fontname) - { + { /* There is no base font name, use the default. */ fontsetname = xmalloc (strlen (base_fontname) + 2); strcpy (fontsetname, base_fontname); @@ -1953,21 +1953,21 @@ xic_create_fontsetname (const char *base_fontname, int motif) /* Build the font spec that matches all charsets. */ len = p - base_fontname + strlen (allcs) + 1; - font_allcs = (char *) alloca (len); + font_allcs = alloca (len); memcpy (font_allcs, base_fontname, p - base_fontname); strcat (font_allcs, allcs); /* Build the font spec that matches all families and add-styles. */ len = p - p1 + strlen (allcs) + strlen (allfamilies) + 1; - font_allfamilies = (char *) alloca (len); + font_allfamilies = alloca (len); strcpy (font_allfamilies, allfamilies); memcpy (font_allfamilies + strlen (allfamilies), p1, p - p1); strcat (font_allfamilies, allcs); /* Build the font spec that matches all. */ len = p - p2 + strlen (allcs) + strlen (all) + strlen (allfamilies) + 1; - font_all = (char *) alloca (len); + font_all = alloca (len); strcpy (font_all, allfamilies); strcat (font_all, all); memcpy (font_all + strlen (all) + strlen (allfamilies), p2, p - p2); @@ -3129,7 +3129,7 @@ This function is an internal primitive--use `make-frame' instead. */) f->terminal = dpyinfo->terminal; f->output_method = output_x_window; - f->output_data.x = xzalloc (sizeof (struct x_output)); + f->output_data.x = xzalloc (sizeof *f->output_data.x); f->output_data.x->icon_bitmap = -1; FRAME_FONTSET (f) = -1; f->output_data.x->scroll_bar_foreground_pixel = -1; @@ -3957,7 +3957,7 @@ select_visual (struct x_display_info *dpyinfo) /* VALUE should be of the form CLASS-DEPTH, where CLASS is one of `PseudoColor', `TrueColor' etc. and DEPTH is the color depth, a decimal number. NAME is compared with case ignored. */ - char *s = (char *) alloca (SBYTES (value) + 1); + char *s = alloca (SBYTES (value) + 1); char *dash; int i, class = -1; XVisualInfo vinfo; @@ -4614,7 +4614,7 @@ x_create_tip_frame (struct x_display_info *dpyinfo, from this point on, x_destroy_window might screw up reference counts etc. */ f->output_method = output_x_window; - f->output_data.x = xzalloc (sizeof (struct x_output)); + f->output_data.x = xzalloc (sizeof *f->output_data.x); f->output_data.x->icon_bitmap = -1; FRAME_FONTSET (f) = -1; f->output_data.x->scroll_bar_foreground_pixel = -1; diff --git a/src/xftfont.c b/src/xftfont.c index bc0c56a0fe0..f999ac662ce 100644 --- a/src/xftfont.c +++ b/src/xftfont.c @@ -527,7 +527,7 @@ xftfont_prepare_face (FRAME_PTR f, struct face *face) } #endif - xftface_info = malloc (sizeof (struct xftface_info)); + xftface_info = malloc (sizeof *xftface_info); if (! xftface_info) return -1; xftfont_get_colors (f, face, face->gc, NULL, diff --git a/src/xgselect.c b/src/xgselect.c index c7348d2c70a..3752056bd76 100644 --- a/src/xgselect.c +++ b/src/xgselect.c @@ -153,6 +153,6 @@ xgselect_initialize (void) { #if defined (USE_GTK) || defined (HAVE_GCONF) || defined (HAVE_GSETTINGS) gfds_size = 128; - gfds = xmalloc (sizeof (*gfds)*gfds_size); + gfds = xmalloc (gfds_size * sizeof *gfds); #endif } diff --git a/src/xmenu.c b/src/xmenu.c index b7dd547737d..5a6390449c4 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -980,8 +980,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) ptrdiff_t specpdl_count = SPECPDL_INDEX (); int previous_menu_items_used = f->menu_bar_items_used; Lisp_Object *previous_items - = (Lisp_Object *) alloca (previous_menu_items_used - * sizeof (Lisp_Object)); + = alloca (previous_menu_items_used * sizeof *previous_items); int subitems; /* If we are making a new widget, its contents are empty, @@ -1028,10 +1027,11 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) menu_items = f->menu_bar_vector; menu_items_allocated = VECTORP (menu_items) ? ASIZE (menu_items) : 0; subitems = ASIZE (items) / 4; - submenu_start = (int *) alloca ((subitems + 1) * sizeof (int)); - submenu_end = (int *) alloca (subitems * sizeof (int)); - submenu_n_panes = (int *) alloca (subitems * sizeof (int)); - submenu_top_level_items = (int *) alloca (subitems * sizeof (int)); + submenu_start = alloca ((subitems + 1) * sizeof *submenu_start); + submenu_end = alloca (subitems * sizeof *submenu_end); + submenu_n_panes = alloca (subitems * sizeof *submenu_n_panes); + submenu_top_level_items = alloca (subitems + * sizeof *submenu_top_level_items); init_menu_items (); for (i = 0; i < subitems; i++) { @@ -1639,9 +1639,9 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, int i; widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0; widget_value **submenu_stack - = (widget_value **) alloca (menu_items_used * sizeof (widget_value *)); + = alloca (menu_items_used * sizeof *submenu_stack); Lisp_Object *subprefix_stack - = (Lisp_Object *) alloca (menu_items_used * sizeof (Lisp_Object)); + = alloca (menu_items_used * sizeof *subprefix_stack); int submenu_depth = 0; int first_pane; @@ -2416,7 +2416,7 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, { /* if alloca is fast, use that to make the space, to reduce gc needs. */ - item_data = (char *) alloca (maxwidth + SBYTES (descrip) + 1); + item_data = alloca (maxwidth + SBYTES (descrip) + 1); memcpy (item_data, SSDATA (item_name), SBYTES (item_name)); for (j = SCHARS (item_name); j < maxwidth; j++) item_data[j] = ' '; diff --git a/src/xrdb.c b/src/xrdb.c index 1e68205b630..624bafa5e92 100644 --- a/src/xrdb.c +++ b/src/xrdb.c @@ -74,10 +74,8 @@ static char * x_get_customization_string (XrmDatabase db, const char *name, const char *class) { - char *full_name - = (char *) alloca (strlen (name) + sizeof ("customization") + 3); - char *full_class - = (char *) alloca (strlen (class) + sizeof ("Customization") + 3); + char *full_name = alloca (strlen (name) + sizeof "customization" + 3); + char *full_class = alloca (strlen (class) + sizeof "Customization" + 3); char *result; sprintf (full_name, "%s.%s", name, "customization"); @@ -206,7 +204,7 @@ magic_file_p (const char *string, ptrdiff_t string_len, const char *class, if (min (PTRDIFF_MAX, SIZE_MAX) / 2 - 1 - path_len < next_len) memory_full (SIZE_MAX); path_size = (path_len + next_len + 1) * 2; - path = (char *) xrealloc (path, path_size); + path = xrealloc (path, path_size); } memcpy (path + path_len, next, next_len); @@ -400,7 +398,7 @@ get_user_db (Display *display) char *xdefault; home = gethomedir (); - xdefault = xmalloc (strlen (home) + sizeof (".Xdefaults")); + xdefault = xmalloc (strlen (home) + sizeof ".Xdefaults"); strcpy (xdefault, home); strcat (xdefault, ".Xdefaults"); db = XrmGetFileDatabase (xdefault); @@ -434,7 +432,7 @@ get_environ_db (void) char *home = gethomedir (); char const *host = get_system_name (); ptrdiff_t pathsize = strlen (home) + sizeof xdefaults + strlen (host); - path = (char *) xrealloc (home, pathsize); + path = xrealloc (home, pathsize); strcat (strcat (path, xdefaults), host); p = path; } diff --git a/src/xselect.c b/src/xselect.c index 67785b26353..e2da561e953 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -180,7 +180,7 @@ x_queue_event (struct input_event *event) } } - queue_tmp = xmalloc (sizeof (struct selection_event_queue)); + queue_tmp = xmalloc (sizeof *queue_tmp); TRACE1 ("QUEUE SELECTION EVENT %p", queue_tmp); queue_tmp->event = *event; queue_tmp->next = selection_queue; @@ -907,7 +907,7 @@ x_convert_selection (struct input_event *event, Lisp_Object selection_symbol, { if (for_multiple) { - cs = xmalloc (sizeof (struct selection_data)); + cs = xmalloc (sizeof *cs); cs->data = (unsigned char *) &conversion_fail_tag; cs->size = 1; cs->format = 32; @@ -924,7 +924,7 @@ x_convert_selection (struct input_event *event, Lisp_Object selection_symbol, } /* Otherwise, record the converted selection to binary. */ - cs = xmalloc (sizeof (struct selection_data)); + cs = xmalloc (sizeof *cs); cs->data = NULL; cs->nofree = 1; cs->property = property; @@ -1775,20 +1775,24 @@ lisp_data_to_selection_data (Display *display, Lisp_Object obj, } else if (SYMBOLP (obj)) { - *data_ret = xmalloc (sizeof (Atom) + 1); + void *data = xmalloc (sizeof (Atom) + 1); + Atom *x_atom_ptr = data; + *data_ret = data; *format_ret = 32; *size_ret = 1; (*data_ret) [sizeof (Atom)] = 0; - (*(Atom **) data_ret) [0] = symbol_to_x_atom (dpyinfo, obj); + *x_atom_ptr = symbol_to_x_atom (dpyinfo, obj); if (NILP (type)) type = QATOM; } else if (RANGED_INTEGERP (X_SHRT_MIN, obj, X_SHRT_MAX)) { - *data_ret = xmalloc (sizeof (short) + 1); + void *data = xmalloc (sizeof (short) + 1); + short *short_ptr = data; + *data_ret = data; *format_ret = 16; *size_ret = 1; (*data_ret) [sizeof (short)] = 0; - (*(short **) data_ret) [0] = XINT (obj); + *short_ptr = XINT (obj); if (NILP (type)) type = QINTEGER; } else if (INTEGERP (obj) @@ -1797,11 +1801,13 @@ lisp_data_to_selection_data (Display *display, Lisp_Object obj, || (CONSP (XCDR (obj)) && INTEGERP (XCAR (XCDR (obj))))))) { - *data_ret = xmalloc (sizeof (unsigned long) + 1); + void *data = xmalloc (sizeof (unsigned long) + 1); + unsigned long *x_long_ptr = data; + *data_ret = data; *format_ret = 32; *size_ret = 1; (*data_ret) [sizeof (unsigned long)] = 0; - (*(unsigned long **) data_ret) [0] = cons_to_x_long (obj); + *x_long_ptr = cons_to_x_long (obj); if (NILP (type)) type = QINTEGER; } else if (VECTORP (obj)) @@ -1816,23 +1822,28 @@ lisp_data_to_selection_data (Display *display, Lisp_Object obj, if (SYMBOLP (AREF (obj, 0))) /* This vector is an ATOM set */ { + void *data; + Atom *x_atoms; if (NILP (type)) type = QATOM; for (i = 0; i < size; i++) if (!SYMBOLP (AREF (obj, i))) signal_error ("All elements of selection vector must have same type", obj); - *data_ret = xnmalloc (size, sizeof (Atom)); + *data_ret = data = xnmalloc (size, sizeof *x_atoms); + x_atoms = data; *format_ret = 32; *size_ret = size; for (i = 0; i < size; i++) - (*(Atom **) data_ret) [i] - = symbol_to_x_atom (dpyinfo, AREF (obj, i)); + x_atoms[i] = symbol_to_x_atom (dpyinfo, AREF (obj, i)); } else /* This vector is an INTEGER set, or something like it */ { int format = 16; int data_size = sizeof (short); + void *data; + unsigned long *x_atoms; + short *shorts; if (NILP (type)) type = QINTEGER; for (i = 0; i < size; i++) { @@ -1847,17 +1858,17 @@ lisp_data_to_selection_data (Display *display, Lisp_Object obj, break; } } - *data_ret = xnmalloc (size, data_size); + *data_ret = data = xnmalloc (size, data_size); + x_atoms = data; + shorts = data; *format_ret = format; *size_ret = size; for (i = 0; i < size; i++) { if (format == 32) - (*((unsigned long **) data_ret)) [i] = - cons_to_x_long (AREF (obj, i)); + x_atoms[i] = cons_to_x_long (AREF (obj, i)); else - (*((short **) data_ret)) [i] = - XINT (AREF (obj, i)); + shorts[i] = XINT (AREF (obj, i)); } } } diff --git a/src/xterm.c b/src/xterm.c index 1562ab08056..b73290ccd00 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -6450,7 +6450,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr, if (status_return == XBufferOverflow) { copy_bufsiz = nbytes + 1; - copy_bufptr = (unsigned char *) alloca (copy_bufsiz); + copy_bufptr = alloca (copy_bufsiz); nbytes = XmbLookupString (FRAME_XIC (f), &event.xkey, (char *) copy_bufptr, copy_bufsiz, &keysym, @@ -7670,7 +7670,7 @@ x_error_catcher (Display *display, XErrorEvent *event) void x_catch_errors (Display *dpy) { - struct x_error_message_stack *data = xmalloc (sizeof (*data)); + struct x_error_message_stack *data = xmalloc (sizeof *data); /* Make sure any errors from previous requests have been dealt with. */ XSync (dpy, False); @@ -7798,7 +7798,7 @@ x_connection_closed (Display *dpy, const char *error_message) Lisp_Object frame, tail; ptrdiff_t idx = SPECPDL_INDEX (); - error_msg = (char *) alloca (strlen (error_message) + 1); + error_msg = alloca (strlen (error_message) + 1); strcpy (error_msg, error_message); handling_signal = 0; @@ -8187,10 +8187,9 @@ xim_initialize (struct x_display_info *dpyinfo, char *resource_name) if (use_xim) { #ifdef HAVE_X11R6_XIM - struct xim_inst_t *xim_inst; + struct xim_inst_t *xim_inst = xmalloc (sizeof *xim_inst); ptrdiff_t len; - xim_inst = xmalloc (sizeof (struct xim_inst_t)); dpyinfo->xim_callback_data = xim_inst; xim_inst->dpyinfo = dpyinfo; len = strlen (resource_name); @@ -10098,7 +10097,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) /* We have definitely succeeded. Record the new connection. */ - dpyinfo = xzalloc (sizeof (struct x_display_info)); + dpyinfo = xzalloc (sizeof *dpyinfo); hlinfo = &dpyinfo->mouse_highlight; terminal = x_create_terminal (dpyinfo); @@ -10116,7 +10115,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) terminal->kboard = share->terminal->kboard; else { - terminal->kboard = xmalloc (sizeof (KBOARD)); + terminal->kboard = xmalloc (sizeof *terminal->kboard); init_kboard (terminal->kboard); KVAR (terminal->kboard, Vwindow_system) = Qx; @@ -10370,8 +10369,8 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) const int atom_count = sizeof (atom_refs) / sizeof (atom_refs[0]); /* 1 for _XSETTINGS_SN */ const int total_atom_count = 1 + atom_count; - Atom *atoms_return = xmalloc (sizeof (Atom) * total_atom_count); - char **atom_names = xmalloc (sizeof (char *) * total_atom_count); + Atom *atoms_return = xmalloc (total_atom_count * sizeof *atoms_return); + char **atom_names = xmalloc (total_atom_count * sizeof *atom_names); static char const xsettings_fmt[] = "_XSETTINGS_S%d"; char xsettings_atom_name[sizeof xsettings_fmt - 2 + INT_STRLEN_BOUND (int)]; @@ -10399,7 +10398,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) dpyinfo->x_dnd_atoms_size = 8; dpyinfo->x_dnd_atoms_length = 0; - dpyinfo->x_dnd_atoms = xmalloc (sizeof (*dpyinfo->x_dnd_atoms) + dpyinfo->x_dnd_atoms = xmalloc (sizeof *dpyinfo->x_dnd_atoms * dpyinfo->x_dnd_atoms_size); dpyinfo->net_supported_atoms = NULL; |