diff options
| author | Dmitry V. Levin <[email protected]> | 2021-09-06 08:00:00 +0000 |
|---|---|---|
| committer | Dmitry V. Levin <[email protected]> | 2021-09-09 08:01:00 +0000 |
| commit | e094270980f1ca8af86a64cee0dbb6f1df670619 (patch) | |
| tree | 1471f9586bb9e3d7f5448001353d47e94145a4ae /src | |
| parent | 02b05e183998943dd5a19ba783b8793e2ab9ab44 (diff) | |
Remove redundant casts of memory allocating functions returning void *
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 <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 13 | ||||
| -rw-r--r-- | src/elflint.c | 2 | ||||
| -rw-r--r-- | src/findtextrel.c | 7 | ||||
| -rw-r--r-- | src/nm.c | 7 | ||||
| -rw-r--r-- | src/readelf.c | 14 | ||||
| -rw-r--r-- | src/strip.c | 9 |
6 files changed, 29 insertions, 23 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index e83e0a5e..1e7968f4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2021-09-06 Dmitry V. Levin <[email protected]> + + * 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 <[email protected]> * Makefile.am (AM_LDFLAGS): Add $(STACK_USAGE_NO_ERROR). diff --git a/src/elflint.c b/src/elflint.c index 35b40500..1ce75684 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -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 diff --git a/src/findtextrel.c b/src/findtextrel.c index 220ee909..5d479b51 100644 --- a/src/findtextrel.c +++ b/src/findtextrel.c @@ -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, _("\ @@ -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 diff --git a/src/readelf.c b/src/readelf.c index 8191bde2..1e3ad43d 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -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) diff --git a/src/strip.c b/src/strip.c index 961b9db5..d5b753d7 100644 --- a/src/strip.c +++ b/src/strip.c @@ -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; |
