From 1a2fa8f413ffacc2490f4c46b3bbfc37b16fbd04 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Wed, 10 Jan 2024 08:18:22 +0100 Subject: [PATCH] Remove redundant casts from void* with malloc functions * src/msdos.c (IT_menu_make_room): * src/pgtkterm.c (pgtk_define_fringe_bitmap): * src/w16select.c (set_clipboard_data): * src/w32term.c (w32_define_fringe_bitmap): * src/w32uniscribe.c (uniscribe_shape): Remove redundant cast from void* with xrealloc. * admin/coccinelle/alloc_cast.cocci: New semantic patch. --- admin/coccinelle/alloc_cast.cocci | 6 ++++++ src/msdos.c | 12 ++++-------- src/pgtkterm.c | 4 +--- src/w16select.c | 2 +- src/w32term.c | 2 +- src/w32uniscribe.c | 3 +-- 6 files changed, 14 insertions(+), 15 deletions(-) create mode 100644 admin/coccinelle/alloc_cast.cocci diff --git a/admin/coccinelle/alloc_cast.cocci b/admin/coccinelle/alloc_cast.cocci new file mode 100644 index 00000000000..91810dbc7e4 --- /dev/null +++ b/admin/coccinelle/alloc_cast.cocci @@ -0,0 +1,6 @@ +// Remove redundant casts from memory allocation functions. +@@ +type T; +@@ +-(T *) + \(xmalloc\|xzalloc\|xrealloc\|xpalloc\|xnrealloc\)(...) diff --git a/src/msdos.c b/src/msdos.c index bdacda50975..1f82d4029d7 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -2811,14 +2811,10 @@ IT_menu_make_room (XMenu *menu) else if (menu->allocated == menu->count) { int count = menu->allocated = menu->allocated + 10; - menu->text - = (char **) xrealloc (menu->text, count * sizeof (char *)); - menu->submenu - = (XMenu **) xrealloc (menu->submenu, count * sizeof (XMenu *)); - menu->panenumber - = (int *) xrealloc (menu->panenumber, count * sizeof (int)); - menu->help_text - = (const char **) xrealloc (menu->help_text, count * sizeof (char *)); + menu->text = xrealloc (menu->text, count * sizeof (char *)); + menu->submenu = xrealloc (menu->submenu, count * sizeof (XMenu *)); + menu->panenumber = xrealloc (menu->panenumber, count * sizeof (int)); + menu->help_text = xrealloc (menu->help_text, count * sizeof (char *)); } } diff --git a/src/pgtkterm.c b/src/pgtkterm.c index d938427c75a..2f7a390d22d 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -3471,9 +3471,7 @@ pgtk_define_fringe_bitmap (int which, unsigned short *bits, int h, int wd) i = max_fringe_bmp; max_fringe_bmp = which + 20; fringe_bmp - = (cairo_pattern_t **) xrealloc (fringe_bmp, - max_fringe_bmp * - sizeof (cairo_pattern_t *)); + = xrealloc (fringe_bmp, max_fringe_bmp * sizeof (cairo_pattern_t *)); while (i < max_fringe_bmp) fringe_bmp[i++] = 0; } diff --git a/src/w16select.c b/src/w16select.c index c8b91bfa883..ed450c665ff 100644 --- a/src/w16select.c +++ b/src/w16select.c @@ -275,7 +275,7 @@ set_clipboard_data (unsigned Format, void *Data, unsigned Size, int Raw) { clipboard_storage_size = truelen + 100; last_clipboard_text = - (char *) xrealloc (last_clipboard_text, clipboard_storage_size); + xrealloc (last_clipboard_text, clipboard_storage_size); } if (last_clipboard_text) dosmemget (xbuf_addr, truelen, last_clipboard_text); diff --git a/src/w32term.c b/src/w32term.c index 816584a13be..f5611772637 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -949,7 +949,7 @@ w32_define_fringe_bitmap (int which, unsigned short *bits, int h, int wd) { int i = max_fringe_bmp; max_fringe_bmp = which + 20; - fringe_bmp = (HBITMAP *) xrealloc (fringe_bmp, max_fringe_bmp * sizeof (HBITMAP)); + fringe_bmp = xrealloc (fringe_bmp, max_fringe_bmp * sizeof (HBITMAP)); while (i < max_fringe_bmp) fringe_bmp[i++] = 0; } diff --git a/src/w32uniscribe.c b/src/w32uniscribe.c index a73c0de06f9..84d0d95b2ab 100644 --- a/src/w32uniscribe.c +++ b/src/w32uniscribe.c @@ -330,8 +330,7 @@ uniscribe_shape (Lisp_Object lgstring, Lisp_Object direction) { /* If that wasn't enough, keep trying with one more run. */ max_items++; - items = (SCRIPT_ITEM *) xrealloc (items, - sizeof (SCRIPT_ITEM) * max_items + 1); + items = xrealloc (items, sizeof (SCRIPT_ITEM) * max_items + 1); } if (FAILED (result)) -- 2.39.2