Remove redundant casts of memory allocating functions returning void *
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 6 Sep 2021 08:00:00 +0000 (08:00 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 9 Sep 2021 08:01:00 +0000 (08:01 +0000)
Return values of functions returning "void *", e.g. calloc, malloc,
realloc, xcalloc, xmalloc, and xrealloc, do not need explicit casts.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
44 files changed:
debuginfod/ChangeLog
debuginfod/debuginfod-client.c
lib/ChangeLog
lib/dynamicsizehash.c
lib/dynamicsizehash_concurrent.c
libasm/ChangeLog
libasm/asm_align.c
libasm/asm_begin.c
libasm/asm_fill.c
libasm/asm_newabssym.c
libasm/asm_newcomsym.c
libasm/asm_newscn.c
libasm/asm_newscngrp.c
libasm/asm_newsubscn.c
libasm/asm_newsym.c
libasm/disasm_begin.c
libdw/ChangeLog
libdw/dwarf_begin_elf.c
libdw/dwarf_getpubnames.c
libdw/dwarf_getsrclines.c
libdwelf/ChangeLog
libdwelf/dwelf_strtab.c
libdwfl/ChangeLog
libdwfl/linux-pid-attach.c
libebl/ChangeLog
libebl/eblopenbackend.c
libelf/ChangeLog
libelf/common.h
libelf/elf32_updatefile.c
libelf/elf_begin.c
libelf/elf_getarsym.c
libelf/elf_getdata.c
libelf/elf_getscn.c
libelf/elf_newdata.c
libelf/elf_newscn.c
libelf/elf_readall.c
src/ChangeLog
src/elflint.c
src/findtextrel.c
src/nm.c
src/readelf.c
src/strip.c
tests/ChangeLog
tests/elfcopy.c

index c545982..7e221f5 100644 (file)
@@ -1,3 +1,8 @@
+2021-09-06  Dmitry V. Levin  <ldv@altlinux.org>
+
+       * debuginfod-client.c (debuginfod_begin): Remove cast of calloc return
+       value.
+
 2021-08-28  Mark Wielaard  <mjw@redhat.com>
 
        * debuginfod.cxx (parse_opt): Turn the -d arg ":memory:" into
index 7d4b220..d41723c 100644 (file)
@@ -1359,7 +1359,7 @@ debuginfod_begin (void)
 {
   debuginfod_client *client;
   size_t size = sizeof (struct debuginfod_client);
-  client = (debuginfod_client *) calloc (1, size);
+  client = calloc (1, size);
 
   if (client != NULL)
     {
index 60d3208..563b0b6 100644 (file)
@@ -1,3 +1,9 @@
+2021-09-06  Dmitry V. Levin  <ldv@altlinux.org>
+
+       * dynamicsizehash.c (INIT(NAME)): Remove cast of calloc return value.
+       * dynamicsizehash_concurrent.c (INIT(NAME)): Remove cast of malloc
+       return value.
+
 2021-08-23  Saleem Abdulrasool  <abdulras@google.com>
 
        * system.h: Remove inline definition for error and error_message_count
index f9406eb..76c86da 100644 (file)
@@ -184,7 +184,7 @@ INIT(NAME) (NAME *htab, size_t init_size)
 #ifdef ITERATE
   htab->first = NULL;
 #endif
-  htab->table = (void *) calloc ((init_size + 1), sizeof (htab->table[0]));
+  htab->table = calloc ((init_size + 1), sizeof (htab->table[0]));
   if (htab->table == NULL)
     return -1;
 
index 2d53bec..4e2e247 100644 (file)
@@ -355,7 +355,7 @@ INIT(NAME) (NAME *htab, size_t init_size)
 
   pthread_rwlock_init(&htab->resize_rwl, NULL);
 
-  htab->table = (void *) malloc ((init_size + 1) * sizeof (htab->table[0]));
+  htab->table = malloc ((init_size + 1) * sizeof (htab->table[0]));
   if (htab->table == NULL)
       return -1;
 
index 85e723e..c65fd21 100644 (file)
@@ -1,3 +1,17 @@
+2021-09-06  Dmitry V. Levin  <ldv@altlinux.org>
+
+       * asm_align.c (__libasm_ensure_section_space): Remove casts of calloc
+       return values.
+       * asm_begin.c (asm_begin): Remove cast of malloc return value.
+       * asm_fill.c (asm_fill): Likewise.
+       * asm_newabssym.c (asm_newabssym): Likewise.
+       * asm_newcomsym.c (asm_newcomsym): Likewise.
+       * asm_newscn.c (asm_newscn): Likewise.
+       * asm_newscngrp.c (asm_newscngrp): Likewise.
+       * asm_newsubscn.c (asm_newsubscn): Likewise.
+       * asm_newsym.c (asm_newsym): Likewise.
+       * disasm_begin.c (disasm_begin): Likewise.
+
 2021-04-19  Martin Liska  <mliska@suse.cz>
 
        * libasmP.h (asm_emit_symbol_p): Use startswith.
index c8c671b..3a97675 100644 (file)
@@ -143,8 +143,7 @@ __libasm_ensure_section_space (AsmScn_t *asmscn, size_t len)
       /* This is the first block.  */
       size = MAX (2 * len, 960);
 
-      asmscn->content = (struct AsmData *) calloc (1, sizeof (struct AsmData)
-                                                  + size);
+      asmscn->content = calloc (1, sizeof (struct AsmData) + size);
       if (asmscn->content == NULL)
        return -1;
 
@@ -160,7 +159,7 @@ __libasm_ensure_section_space (AsmScn_t *asmscn, size_t len)
 
       size = MAX (2 *len, MIN (32768, 2 * asmscn->offset));
 
-      newp = (struct AsmData *) calloc (1, sizeof (struct AsmData) + size);
+      newp = calloc (1, sizeof (struct AsmData) + size);
       if (newp == NULL)
        return -1;
 
index 1df2d4e..a190202 100644 (file)
@@ -138,8 +138,7 @@ asm_begin (const char *fname, Ebl *ebl, bool textp)
      right away.  Instead we create a temporary file in the same
      directory which, if everything goes alright, will replace a
      possibly existing file with the given name.  */
-  AsmCtx_t *result
-    = (AsmCtx_t *) malloc (sizeof (AsmCtx_t) + 2 * fname_len + 9);
+  AsmCtx_t *result = malloc (sizeof (AsmCtx_t) + 2 * fname_len + 9);
   if (result == NULL)
     return NULL;
 
index 62d9d73..783555e 100644 (file)
@@ -54,8 +54,7 @@ asm_fill (AsmScn_t *asmscn, void *bytes, size_t len)
   else
     {
       /* Allocate appropriate memory.  */
-      pattern = (struct FillPattern *) malloc (sizeof (struct FillPattern)
-                                              + len);
+      pattern = malloc (sizeof (struct FillPattern) + len);
       if (pattern == NULL)
        return -1;
 
index 34fef3e..728d604 100644 (file)
@@ -71,7 +71,7 @@ asm_newabssym (AsmCtx_t *ctx, const char *name, GElf_Xword size,
 
   rwlock_wrlock (ctx->lock);
 
-  result = (AsmSym_t *) malloc (sizeof (AsmSym_t));
+  result = malloc (sizeof (AsmSym_t));
   if (result == NULL)
     return NULL;
 
index ee3b696..750a138 100644 (file)
@@ -71,7 +71,7 @@ asm_newcomsym (AsmCtx_t *ctx, const char *name, GElf_Xword size,
 
   rwlock_wrlock (ctx->lock);
 
-  result = (AsmSym_t *) malloc (sizeof (AsmSym_t));
+  result = malloc (sizeof (AsmSym_t));
   if (result == NULL)
     return NULL;
 
index 7cdf484..1150015 100644 (file)
@@ -181,7 +181,7 @@ asm_newscn (AsmCtx_t *ctx, const char *scnname, GElf_Word type,
   rwlock_wrlock (ctx->lock);
 
   /* This is a new section.  */
-  result = (AsmScn_t *) malloc (sizeof (AsmScn_t) + scnname_len);
+  result = malloc (sizeof (AsmScn_t) + scnname_len);
   if (result != NULL)
     {
       /* Add the name.  */
index 80757a9..0ca87fb 100644 (file)
@@ -57,7 +57,7 @@ asm_newscngrp (AsmCtx_t *ctx, const char *grpname, AsmSym_t *signature,
       return NULL;
     }
 
-  result = (AsmScnGrp_t *) malloc (sizeof (AsmScnGrp_t) + grpname_len);
+  result = malloc (sizeof (AsmScnGrp_t) + grpname_len);
   if (result == NULL)
     return NULL;
 
index 906240a..2f2ba78 100644 (file)
@@ -62,7 +62,7 @@ asm_newsubscn (AsmScn_t *asmscn, unsigned int nr)
       runp = runp->subnext;
     }
 
-  newp = (AsmScn_t *) malloc (sizeof (AsmScn_t));
+  newp = malloc (sizeof (AsmScn_t));
   if (newp == NULL)
     return NULL;
 
index 5389166..a89ee12 100644 (file)
@@ -73,7 +73,7 @@ asm_newsym (AsmScn_t *asmscn, const char *name, GElf_Xword size,
 
   size_t name_len = strlen (name) + 1;
 
-  result = (AsmSym_t *) malloc (sizeof (AsmSym_t) + name_len);
+  result = malloc (sizeof (AsmSym_t) + name_len);
   if (result == NULL)
     return NULL;
 
index d00852b..cb10f66 100644 (file)
@@ -49,7 +49,7 @@ disasm_begin (Ebl *ebl, Elf *elf, DisasmGetSymCB_t symcb)
       return NULL;
     }
 
-  DisasmCtx_t *ctx = (DisasmCtx_t *) malloc (sizeof (DisasmCtx_t));
+  DisasmCtx_t *ctx = malloc (sizeof (DisasmCtx_t));
   if (ctx == NULL)
     {
       __libasm_seterrno (ASM_E_NOMEM);
index b5462ef..768d5c2 100644 (file)
@@ -1,3 +1,12 @@
+2021-09-06  Dmitry V. Levin  <ldv@altlinux.org>
+
+       * dwarf_begin_elf.c (valid_p): Remove casts of malloc return values.
+       (dwarf_begin_elf): Remove cast of calloc return value.
+       * dwarf_getpubnames.c (get_offsets): Remove casts of realloc return
+       values.
+       * dwarf_getsrclines.c (read_srclines): Remove cast of malloc return
+       value.
+
 2021-04-19  Martin Liska  <mliska@suse.cz>
 
        * dwarf_begin_elf.c (check_section): Use startswith.
index 9e944b8..7bde61b 100644 (file)
@@ -229,7 +229,7 @@ valid_p (Dwarf *result)
      inside the .debug_loc or .debug_loclists section.  */
   if (result != NULL && result->sectiondata[IDX_debug_loc] != NULL)
     {
-      result->fake_loc_cu = (Dwarf_CU *) malloc (sizeof (Dwarf_CU));
+      result->fake_loc_cu = malloc (sizeof (Dwarf_CU));
       if (unlikely (result->fake_loc_cu == NULL))
        {
          Dwarf_Sig8_Hash_free (&result->sig8_hash);
@@ -255,7 +255,7 @@ valid_p (Dwarf *result)
 
   if (result != NULL && result->sectiondata[IDX_debug_loclists] != NULL)
     {
-      result->fake_loclists_cu = (Dwarf_CU *) malloc (sizeof (Dwarf_CU));
+      result->fake_loclists_cu = malloc (sizeof (Dwarf_CU));
       if (unlikely (result->fake_loclists_cu == NULL))
        {
          Dwarf_Sig8_Hash_free (&result->sig8_hash);
@@ -286,7 +286,7 @@ valid_p (Dwarf *result)
      inside the .debug_addr section, if it exists.  */
   if (result != NULL && result->sectiondata[IDX_debug_addr] != NULL)
     {
-      result->fake_addr_cu = (Dwarf_CU *) malloc (sizeof (Dwarf_CU));
+      result->fake_addr_cu = malloc (sizeof (Dwarf_CU));
       if (unlikely (result->fake_addr_cu == NULL))
        {
          Dwarf_Sig8_Hash_free (&result->sig8_hash);
@@ -415,7 +415,7 @@ dwarf_begin_elf (Elf *elf, Dwarf_Cmd cmd, Elf_Scn *scngrp)
   assert (sizeof (struct Dwarf) < mem_default_size);
 
   /* Allocate the data structure.  */
-  Dwarf *result = (Dwarf *) calloc (1, sizeof (Dwarf));
+  Dwarf *result = calloc (1, sizeof (Dwarf));
   if (unlikely (result == NULL)
       || unlikely (Dwarf_Sig8_Hash_init (&result->sig8_hash, 11) < 0))
     {
index 25600f3..de72640 100644 (file)
@@ -57,8 +57,7 @@ get_offsets (Dwarf *dbg)
       if (cnt >= allocated)
        {
          allocated = MAX (10, 2 * allocated);
-         struct pubnames_s *newmem
-           = (struct pubnames_s *) realloc (mem, allocated * entsize);
+         struct pubnames_s *newmem = realloc (mem, allocated * entsize);
          if (newmem == NULL)
            {
              __libdw_seterrno (DWARF_E_NOMEM);
@@ -132,7 +131,7 @@ get_offsets (Dwarf *dbg)
       return -1;
     }
 
-  dbg->pubnames_sets = (struct pubnames_s *) realloc (mem, cnt * entsize);
+  dbg->pubnames_sets = realloc (mem, cnt * entsize);
   dbg->pubnames_nsets = cnt;
 
   return 0;
index d6a581a..8fc48e1 100644 (file)
@@ -372,7 +372,7 @@ read_srclines (Dwarf *dbg,
     {
       if (ndirlist > SIZE_MAX / sizeof (*dirarray))
        goto no_mem;
-      dirarray = (struct dirlist *) malloc (ndirlist * sizeof (*dirarray));
+      dirarray = malloc (ndirlist * sizeof (*dirarray));
       if (unlikely (dirarray == NULL))
        {
        no_mem:
index a0ff9f4..1abee0e 100644 (file)
@@ -1,3 +1,9 @@
+2021-09-06  Dmitry V. Levin  <ldv@altlinux.org>
+
+       * dwelf_strtab.c (dwelf_strtab_init): Remove cast of calloc return
+       value.
+       (morememory): Remove cast of malloc return value.
+
 2020-12-12  Dmitry V. Levin  <ldv@altlinux.org>
 
        * libdwelf.h: Fix spelling typos in comments.
index c6ae7cd..5ec8c29 100644 (file)
@@ -91,8 +91,7 @@ dwelf_strtab_init (bool nullstr)
       assert (sizeof (struct memoryblock) < ps - MALLOC_OVERHEAD);
     }
 
-  Dwelf_Strtab *ret
-    = (Dwelf_Strtab *) calloc (1, sizeof (struct Dwelf_Strtab));
+  Dwelf_Strtab *ret = calloc (1, sizeof (struct Dwelf_Strtab));
   if (ret != NULL)
     {
       ret->nullstr = nullstr;
@@ -117,7 +116,7 @@ morememory (Dwelf_Strtab *st, size_t len)
   /* Allocate nearest multiple of pagesize >= len.  */
   len = ((len / ps) + (len % ps != 0)) * ps - MALLOC_OVERHEAD;
 
-  struct memoryblock *newmem = (struct memoryblock *) malloc (len);
+  struct memoryblock *newmem = malloc (len);
   if (newmem == NULL)
     return 1;
 
index 1fce7af..d35674c 100644 (file)
@@ -1,3 +1,8 @@
+2021-09-06  Dmitry V. Levin  <ldv@altlinux.org>
+
+       * linux-pid-attach.c (read_cached_memory): Remove cast of malloc
+       return value.
+
 2021-06-09  Omar Sandoval  <osandov@fb.com>
 
        * link_map.c (read_addrs): Fix potential NULL pointer dereference.
index cd53482..09cba07 100644 (file)
@@ -135,7 +135,7 @@ read_cached_memory (struct __libdwfl_pid_arg *pid_arg,
   if (mem_cache == NULL)
     {
       size_t mem_cache_size = sizeof (struct __libdwfl_remote_mem_cache);
-      mem_cache = (struct __libdwfl_remote_mem_cache *) malloc (mem_cache_size);
+      mem_cache = malloc (mem_cache_size);
       if (mem_cache == NULL)
        return false;
 
index fff66b3..da690a4 100644 (file)
@@ -1,3 +1,7 @@
+2021-09-06  Dmitry V. Levin  <ldv@altlinux.org>
+
+       * eblopenbackend.c (openbackend): Remove cast of calloc return value.
+
 2021-04-19  Martin Liska  <mliska@suse.cz>
 
        * eblobjnotetypename.c (ebl_object_note_type_name): Use startswith.
index 71fafed..0c07296 100644 (file)
@@ -274,7 +274,7 @@ openbackend (Elf *elf, const char *emulation, GElf_Half machine)
   /* First allocate the data structure for the result.  We do this
      here since this assures that the structure is always large
      enough.  */
-  result = (Ebl *) calloc (1, sizeof (Ebl));
+  result = calloc (1, sizeof (Ebl));
   if (result == NULL)
     {
       // XXX uncomment
index f521ed3..041da9b 100644 (file)
@@ -1,3 +1,17 @@
+2021-09-06  Dmitry V. Levin  <ldv@altlinux.org>
+
+       * common.h (allocate_elf): Remove cast of calloc return value.
+       * elf_newdata.c (elf_newdata): Likewise.
+       * elf_getscn.c (elf_getscn): Remove casts of calloc return values.
+       * elf_newscn.c (elf_newscn): Likewise.
+       * elf32_updatefile.c (__elfw2): Remove casts of malloc return values.
+       * elf_getdata.c (convert_data): Likewise.
+       (__libelf_set_rawdata_wrlock): Remove cast of malloc return value.
+       * elf_begin.c (read_long_names): Remove cast of malloc return value.
+       * elf_readall.c (__libelf_readall): Likewise.
+       * elf_getarsym.c (elf_getarsym): Remove casts of malloc and realloc
+       return values.
+
 2021-07-19  Mark Wielaard  <mark@klomp.org>
 
        * elf_strptr.c (validate_str): Check last char is zero first before
index e41c717..3718b3f 100644 (file)
@@ -71,7 +71,7 @@ __attribute__ ((unused))
 allocate_elf (int fildes, void *map_address, int64_t offset, size_t maxsize,
               Elf_Cmd cmd, Elf *parent, Elf_Kind kind, size_t extra)
 {
-  Elf *result = (Elf *) calloc (1, sizeof (Elf) + extra);
+  Elf *result = calloc (1, sizeof (Elf) + extra);
   if (result == NULL)
     __libelf_seterrno (ELF_E_NOMEM);
   else
index f67e626..1ff5890 100644 (file)
@@ -218,7 +218,7 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
        return 1;
 
       Elf_ScnList *list = &elf->state.ELFW(elf,LIBELFBITS).scns;
-      Elf_Scn **scns = (Elf_Scn **) malloc (shnum * sizeof (Elf_Scn *));
+      Elf_Scn **scns = malloc (shnum * sizeof (Elf_Scn *));
       if (unlikely (scns == NULL))
        {
          __libelf_seterrno (ELF_E_NOMEM);
@@ -688,7 +688,7 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum)
 
       /* Get all sections into the array and sort them.  */
       Elf_ScnList *list = &elf->state.ELFW(elf,LIBELFBITS).scns;
-      Elf_Scn **scns = (Elf_Scn **) malloc (shnum * sizeof (Elf_Scn *));
+      Elf_Scn **scns = malloc (shnum * sizeof (Elf_Scn *));
       if (unlikely (scns == NULL))
        {
          free (shdr_data_mem);
index 32648c1..93d1e12 100644 (file)
@@ -774,7 +774,7 @@ read_long_names (Elf *elf)
   /* Due to the stupid format of the long name table entry (which are not
      NUL terminted) we have to provide an appropriate representation anyhow.
      Therefore we always make a copy which has the appropriate form.  */
-  newp = (char *) malloc (len);
+  newp = malloc (len);
   if (newp != NULL)
     {
       char *runp;
index 1f031fc..05ebf6a 100644 (file)
@@ -198,7 +198,7 @@ elf_getarsym (Elf *elf, size_t *ptr)
 
       /* Now we can allocate the arrays needed to store the index.  */
       size_t ar_sym_len = (n + 1) * sizeof (Elf_Arsym);
-      elf->state.ar.ar_sym = (Elf_Arsym *) malloc (ar_sym_len);
+      elf->state.ar.ar_sym = malloc (ar_sym_len);
       if (elf->state.ar.ar_sym != NULL)
        {
          void *file_data; /* unit32_t[n] or uint64_t[n] */
@@ -216,8 +216,7 @@ elf_getarsym (Elf *elf, size_t *ptr)
              file_data = temp_data;
 
              ar_sym_len += index_size - n * w;
-             Elf_Arsym *newp = (Elf_Arsym *) realloc (elf->state.ar.ar_sym,
-                                                      ar_sym_len);
+             Elf_Arsym *newp = realloc (elf->state.ar.ar_sym, ar_sym_len);
              if (newp == NULL)
                {
                  free (elf->state.ar.ar_sym);
index 3cad29d..475c6de 100644 (file)
@@ -146,7 +146,7 @@ convert_data (Elf_Scn *scn, int eclass,
        scn->data_base = scn->rawdata_base;
       else
        {
-         scn->data_base = (char *) malloc (size);
+         scn->data_base = malloc (size);
          if (scn->data_base == NULL)
            {
              __libelf_seterrno (ELF_E_NOMEM);
@@ -161,7 +161,7 @@ convert_data (Elf_Scn *scn, int eclass,
     {
       xfct_t fp;
 
-      scn->data_base = (char *) malloc (size);
+      scn->data_base = malloc (size);
       if (scn->data_base == NULL)
        {
          __libelf_seterrno (ELF_E_NOMEM);
@@ -175,7 +175,7 @@ convert_data (Elf_Scn *scn, int eclass,
        rawdata_source = scn->rawdata_base;
       else
        {
-         rawdata_source = (char *) malloc (size);
+         rawdata_source = malloc (size);
          if (rawdata_source == NULL)
            {
              __libelf_seterrno (ELF_E_NOMEM);
@@ -328,8 +328,7 @@ __libelf_set_rawdata_wrlock (Elf_Scn *scn)
 
          /* We have to read the data from the file.  Allocate the needed
             memory.  */
-         scn->rawdata_base = scn->rawdata.d.d_buf
-           = (char *) malloc (size);
+         scn->rawdata_base = scn->rawdata.d.d_buf = malloc (size);
          if (scn->rawdata.d.d_buf == NULL)
            {
              __libelf_seterrno (ELF_E_NOMEM);
index e1fbaaa..be9c76f 100644 (file)
@@ -68,7 +68,7 @@ elf_getscn (Elf *elf, size_t idx)
       Elf_Scn *scn0 = &runp->data[0];
       if (elf->class == ELFCLASS32)
        {
-         scn0->shdr.e32 = (Elf32_Shdr *) calloc (1, sizeof (Elf32_Shdr));
+         scn0->shdr.e32 = calloc (1, sizeof (Elf32_Shdr));
          if (scn0->shdr.e32 == NULL)
            {
              __libelf_seterrno (ELF_E_NOMEM);
@@ -77,7 +77,7 @@ elf_getscn (Elf *elf, size_t idx)
        }
       else
        {
-         scn0->shdr.e64 = (Elf64_Shdr *) calloc (1, sizeof (Elf64_Shdr));
+         scn0->shdr.e64 = calloc (1, sizeof (Elf64_Shdr));
          if (scn0->shdr.e64 == NULL)
            {
              __libelf_seterrno (ELF_E_NOMEM);
index 896f22c..0063d59 100644 (file)
@@ -106,7 +106,7 @@ elf_newdata (Elf_Scn *scn)
        }
 
       /* Create a new, empty data descriptor.  */
-      result = (Elf_Data_List *) calloc (1, sizeof (Elf_Data_List));
+      result = calloc (1, sizeof (Elf_Data_List));
       if (result == NULL)
        {
          __libelf_seterrno (ELF_E_NOMEM);
index d15a642..d6bdf15 100644 (file)
@@ -94,9 +94,9 @@ elf_newscn (Elf *elf)
          1
 #endif
          )
-      newp = (Elf_ScnList *) calloc (sizeof (Elf_ScnList)
-                                    + ((elf->state.elf.scnincr *= 2)
-                                       * sizeof (Elf_Scn)), 1);
+      newp = calloc (sizeof (Elf_ScnList)
+                    + ((elf->state.elf.scnincr *= 2)
+                       * sizeof (Elf_Scn)), 1);
       if (newp == NULL)
        {
          __libelf_seterrno (ELF_E_NOMEM);
@@ -122,7 +122,7 @@ elf_newscn (Elf *elf)
   /* Create a section header for this section.  */
   if (elf->class == ELFCLASS32)
     {
-      result->shdr.e32 = (Elf32_Shdr *) calloc (1, sizeof (Elf32_Shdr));
+      result->shdr.e32 = calloc (1, sizeof (Elf32_Shdr));
       if (result->shdr.e32 == NULL)
        {
          __libelf_seterrno (ELF_E_NOMEM);
@@ -131,7 +131,7 @@ elf_newscn (Elf *elf)
     }
   else
     {
-      result->shdr.e64 = (Elf64_Shdr *) calloc (1, sizeof (Elf64_Shdr));
+      result->shdr.e64 = calloc (1, sizeof (Elf64_Shdr));
       if (result->shdr.e64 == NULL)
        {
          __libelf_seterrno (ELF_E_NOMEM);
index 384d251..0a3a233 100644 (file)
@@ -107,7 +107,7 @@ __libelf_readall (Elf *elf)
        }
 
       /* Allocate all the memory we need.  */
-      mem = (char *) malloc (elf->maximum_size);
+      mem = malloc (elf->maximum_size);
       if (mem != NULL)
        {
          /* Read the file content.  */
index e83e0a5..1e7968f 100644 (file)
@@ -1,3 +1,16 @@
+2021-09-06  Dmitry V. Levin  <ldv@altlinux.org>
+
+       * elflint.c (check_sections): Remove cast of xcalloc return value.
+       * findtextrel.c (process_file): Remove casts of malloc and realloc
+       return values.
+       * nm.c (get_local_names, show_symbols_sysv, show_symbols): Remove
+       casts of xmalloc return values.
+       * readelf.c (print_hash_info, handle_sysv_hash, handle_sysv_hash64,
+       handle_gnu_hash): Remove cast of xcalloc return value.
+       (print_debug_units): Remove casts of xmalloc return values.
+       * strip.c (handle_elf): Remove casts of xcalloc and xmalloc return
+       values.
+
 2021-09-05  Dmitry V. Levin  <ldv@altlinux.org>
 
        * Makefile.am (AM_LDFLAGS): Add $(STACK_USAGE_NO_ERROR).
index 35b4050..1ce7568 100644 (file)
@@ -3705,7 +3705,7 @@ check_sections (Ebl *ebl, GElf_Ehdr *ehdr)
     return;
 
   /* Allocate array to count references in section groups.  */
-  scnref = (int *) xcalloc (shnum, sizeof (int));
+  scnref = xcalloc (shnum, sizeof (int));
 
   /* Check the zeroth section first.  It must not have any contents
      and the section header must contain nonzero value at most in the
index 220ee90..5d479b5 100644 (file)
@@ -304,8 +304,7 @@ process_file (const char *fname, bool more_than_one)
   /* Get the address ranges for the loaded segments.  */
   size_t nsegments_max = 10;
   size_t nsegments = 0;
-  struct segments *segments
-    = (struct segments *) malloc (nsegments_max * sizeof (segments[0]));
+  struct segments *segments = malloc (nsegments_max * sizeof (segments[0]));
   if (segments == NULL)
     error (1, errno, _("while reading ELF file"));
 
@@ -334,9 +333,7 @@ process_file (const char *fname, bool more_than_one)
            {
              nsegments_max *= 2;
              segments
-               = (struct segments *) realloc (segments,
-                                              nsegments_max
-                                              * sizeof (segments[0]));
+               = realloc (segments, nsegments_max * sizeof (segments[0]));
              if (segments == NULL)
                {
                  error (0, 0, _("\
index b99805e..2ae29c4 100644 (file)
--- a/src/nm.c
+++ b/src/nm.c
@@ -687,8 +687,7 @@ get_local_names (Dwarf *dbg)
              }
 
            /* We have all the information.  Create a record.  */
-           struct local_name *newp
-             = (struct local_name *) xmalloc (sizeof (*newp));
+           struct local_name *newp = xmalloc (sizeof (*newp));
            newp->name = name;
            newp->file = dwarf_filesrc (files, fileidx, NULL, NULL);
            newp->lineno = lineno;
@@ -736,7 +735,7 @@ show_symbols_sysv (Ebl *ebl, GElf_Word strndx, const char *fullname,
   bool scnnames_malloced = shnum * sizeof (const char *) > 128 * 1024;
   const char **scnnames;
   if (scnnames_malloced)
-    scnnames = (const char **) xmalloc (sizeof (const char *) * shnum);
+    scnnames = xmalloc (sizeof (const char *) * shnum);
   else
     scnnames = (const char **) alloca (sizeof (const char *) * shnum);
   /* Get the section header string table index.  */
@@ -1340,7 +1339,7 @@ show_symbols (int fd, Ebl *ebl, GElf_Ehdr *ehdr,
   if (nentries * sizeof (GElf_SymX) < MAX_STACK_ALLOC)
     sym_mem = (GElf_SymX *) alloca (nentries * sizeof (GElf_SymX));
   else
-    sym_mem = (GElf_SymX *) xmalloc (nentries * sizeof (GElf_SymX));
+    sym_mem = xmalloc (nentries * sizeof (GElf_SymX));
 
   /* Iterate over all symbols.  */
 #ifdef USE_DEMANGLE
index 8191bde..1e3ad43 100644 (file)
@@ -3165,7 +3165,7 @@ print_hash_info (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, size_t shstrndx,
                 uint_fast32_t maxlength, Elf32_Word nbucket,
                 uint_fast32_t nsyms, uint32_t *lengths, const char *extrastr)
 {
-  uint32_t *counts = (uint32_t *) xcalloc (maxlength + 1, sizeof (uint32_t));
+  uint32_t *counts = xcalloc (maxlength + 1, sizeof (uint32_t));
 
   for (Elf32_Word cnt = 0; cnt < nbucket; ++cnt)
     ++counts[lengths[cnt]];
@@ -3266,7 +3266,7 @@ handle_sysv_hash (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, size_t shstrndx)
   Elf32_Word *bucket = &((Elf32_Word *) data->d_buf)[2];
   Elf32_Word *chain = &((Elf32_Word *) data->d_buf)[2 + nbucket];
 
-  uint32_t *lengths = (uint32_t *) xcalloc (nbucket, sizeof (uint32_t));
+  uint32_t *lengths = xcalloc (nbucket, sizeof (uint32_t));
 
   uint_fast32_t maxlength = 0;
   uint_fast32_t nsyms = 0;
@@ -3332,7 +3332,7 @@ handle_sysv_hash64 (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, size_t shstrndx)
   Elf64_Xword *bucket = &((Elf64_Xword *) data->d_buf)[2];
   Elf64_Xword *chain = &((Elf64_Xword *) data->d_buf)[2 + nbucket];
 
-  uint32_t *lengths = (uint32_t *) xcalloc (nbucket, sizeof (uint32_t));
+  uint32_t *lengths = xcalloc (nbucket, sizeof (uint32_t));
 
   uint_fast32_t maxlength = 0;
   uint_fast32_t nsyms = 0;
@@ -3410,7 +3410,7 @@ handle_gnu_hash (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, size_t shstrndx)
   if (used_buf > data->d_size)
     goto invalid_data;
 
-  lengths = (uint32_t *) xcalloc (nbucket, sizeof (uint32_t));
+  lengths = xcalloc (nbucket, sizeof (uint32_t));
 
   Elf32_Word *bitmask = &((Elf32_Word *) data->d_buf)[4];
   Elf32_Word *bucket = &((Elf32_Word *) data->d_buf)[4 + bitmask_words];
@@ -7744,7 +7744,7 @@ print_debug_units (Dwfl_Module *dwflmod,
     return;
 
   int maxdies = 20;
-  Dwarf_Die *dies = (Dwarf_Die *) xmalloc (maxdies * sizeof (Dwarf_Die));
+  Dwarf_Die *dies = xmalloc (maxdies * sizeof (Dwarf_Die));
 
   /* New compilation unit.  */
   Dwarf_Half version;
@@ -7916,9 +7916,7 @@ print_debug_units (Dwfl_Module *dwflmod,
 
       /* Make room for the next level's DIE.  */
       if (level + 1 == maxdies)
-       dies = (Dwarf_Die *) xrealloc (dies,
-                                      (maxdies += 10)
-                                      * sizeof (Dwarf_Die));
+       dies = xrealloc (dies, (maxdies += 10) * sizeof (Dwarf_Die));
 
       int res = dwarf_child (&dies[level], &dies[level + 1]);
       if (res > 0)
index 961b9db..d5b753d 100644 (file)
@@ -1062,7 +1062,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
         the debug file if the file would not contain any
         information.  */
       size_t debug_fname_len = strlen (debug_fname);
-      tmp_debug_fname = (char *) xmalloc (debug_fname_len + sizeof (".XXXXXX"));
+      tmp_debug_fname = xmalloc (debug_fname_len + sizeof (".XXXXXX"));
       strcpy (mempcpy (tmp_debug_fname, debug_fname, debug_fname_len),
              ".XXXXXX");
 
@@ -1196,8 +1196,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
      table.  Maybe some weird tool created an ELF file without one.
      The other one is used for the debug link section.  */
   if ((shnum + 2) * sizeof (struct shdr_info) > MAX_STACK_ALLOC)
-    shdr_info = (struct shdr_info *) xcalloc (shnum + 2,
-                                             sizeof (struct shdr_info));
+    shdr_info = xcalloc (shnum + 2, sizeof (struct shdr_info));
   else
     {
       shdr_info = (struct shdr_info *) alloca ((shnum + 2)
@@ -1980,8 +1979,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
                  }
 
                shdr_info[cnt].newsymidx
-                 = (Elf32_Word *) xcalloc (shdr_info[cnt].data->d_size
-                                           / elsize, sizeof (Elf32_Word));
+                 = xcalloc (shdr_info[cnt].data->d_size / elsize,
+                            sizeof (Elf32_Word));
 
                bool last_was_local = true;
                size_t destidx;
index 42989d1..85dca44 100644 (file)
@@ -1,3 +1,7 @@
+2021-09-06  Dmitry V. Levin  <ldv@altlinux.org>
+
+       * elfcopy.c (copy_elf): Remove cast of malloc return value.
+
 2021-09-07  Mark Wielaard  <mark@klomp.org>
 
        * run-debuginfod-archive-groom.sh: Wait for initial scan and groom
index 4542222..10b2d36 100644 (file)
@@ -194,7 +194,7 @@ copy_elf (const char *in, const char *out, bool use_mmap, bool reverse_offs)
          exit (1);
        }
 
-      offs = (GElf_Off *) malloc (shnum * sizeof (GElf_Off));
+      offs = malloc (shnum * sizeof (GElf_Off));
       if (offs == NULL)
        {
          printf ("couldn't allocate memory for offs\n");