diff options
author | H. Peter Anvin <hpa@zytor.com> | 2017-04-23 17:02:46 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2017-04-23 17:02:46 -0700 |
commit | 3e555483b30c6f0bd4b348861f694f73e487c134 (patch) | |
tree | ed41b485387185e2bb0f992ff1599b419bc31f78 | |
parent | 4dfbd9aec56577d7e0dc9398781ea9918dbdcbf6 (diff) | |
download | nasm-3e555483b30c6f0bd4b348861f694f73e487c134.tar.gz |
labels, outelf: remove casts for allocations
Remove casts from allocations. This is simply Not How To Do Things:
every cast carries a potential risk of being a toxic type misuse
(e.g. pointer as integer) and so any unnecessary cast is actively
harmful.
Note that a lot of allocations here are completely unnecessary: the
core code now guarantees that all filenames are permanently allocated
for the duration of the assembly, and so should be turned into const
char * without any further allocation. Any remaining malloc+strcpy
should be turned into nasm_strdup(), and nasm_new[n]() used whereever
possible.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r-- | asm/labels.c | 8 | ||||
-rw-r--r-- | output/outelf.c | 20 |
2 files changed, 14 insertions, 14 deletions
diff --git a/asm/labels.c b/asm/labels.c index 8c2223a0..1183151c 100644 --- a/asm/labels.c +++ b/asm/labels.c @@ -186,7 +186,7 @@ static union label *find_label(const char *label, int create, int *created) /* * must allocate a new block */ - lfree->admin.next = (union label *)nasm_malloc(LBLK_SIZE); + lfree->admin.next = nasm_malloc(LBLK_SIZE); lfree = lfree->admin.next; init_block(lfree); } @@ -424,11 +424,11 @@ int init_labels(void) { hash_init(<ab, HASH_LARGE); - ldata = lfree = (union label *)nasm_malloc(LBLK_SIZE); + ldata = lfree = nasm_malloc(LBLK_SIZE); init_block(lfree); perm_head = perm_tail = - (struct permts *)nasm_malloc(sizeof(struct permts)); + nasm_malloc(sizeof(struct permts)); perm_head->next = NULL; perm_head->size = PERMTS_SIZE; @@ -483,7 +483,7 @@ static char *perm_copy(const char *string) if (perm_tail->size - perm_tail->usage < len) { perm_tail->next = - (struct permts *)nasm_malloc(sizeof(struct permts)); + nasm_malloc(sizeof(struct permts)); perm_tail = perm_tail->next; perm_tail->next = NULL; perm_tail->size = PERMTS_SIZE; diff --git a/output/outelf.c b/output/outelf.c index 86cb985c..1ee6dacc 100644 --- a/output/outelf.c +++ b/output/outelf.c @@ -2468,7 +2468,7 @@ static void stabs_linenum(const char *filename, int32_t linenumber, int32_t segt { (void)segto; if (!stabs_filename) { - stabs_filename = (char *)nasm_malloc(strlen(filename) + 1); + stabs_filename = nasm_malloc(strlen(filename) + 1); strcpy(stabs_filename, filename); } else { if (strcmp(stabs_filename, filename)) { @@ -2478,7 +2478,7 @@ static void stabs_linenum(const char *filename, int32_t linenumber, int32_t segt /* why not nasm_free(stabs_filename); we're done with the old one */ - stabs_filename = (char *)nasm_malloc(strlen(filename) + 1); + stabs_filename = nasm_malloc(strlen(filename) + 1); strcpy(stabs_filename, filename); } } @@ -2496,7 +2496,7 @@ static void stabs_output(int type, void *param) if (!(sects[s->section]->flags & SHF_EXECINSTR)) return; /* line info is only collected for executable sections */ numlinestabs++; - el = (struct linelist *)nasm_malloc(sizeof(struct linelist)); + el = nasm_malloc(sizeof(struct linelist)); el->info.offset = s->offset; el->info.section = s->section; el->info.name = s->name; @@ -2528,7 +2528,7 @@ static void stabs_generate(void) ptr = stabslines; - allfiles = (char **)nasm_zalloc(numlinestabs * sizeof(char *)); + allfiles = nasm_zalloc(numlinestabs * sizeof(char *)); numfiles = 0; while (ptr) { if (numfiles == 0) { @@ -2547,7 +2547,7 @@ static void stabs_generate(void) ptr = ptr->next; } strsize = 1; - fileidx = (int *)nasm_malloc(numfiles * sizeof(int)); + fileidx = nasm_malloc(numfiles * sizeof(int)); for (i = 0; i < numfiles; i++) { fileidx[i] = strsize; strsize += strlen(allfiles[i]) + 1; @@ -2565,10 +2565,10 @@ static void stabs_generate(void) * the sourcefiles changes each line, which would mean 1 SOL, 1 SYMLIN per line * plus one "ending" entry */ - sbuf = (uint8_t *)nasm_malloc((numlinestabs * 2 + 4) * + sbuf = nasm_malloc((numlinestabs * 2 + 4) * sizeof(struct stabentry)); - ssbuf = (uint8_t *)nasm_malloc(strsize); - rbuf = (uint8_t *)nasm_malloc(numlinestabs * (is_elf64() ? 16 : 8) * (2 + 3)); + ssbuf = nasm_malloc(strsize); + rbuf = nasm_malloc(numlinestabs * (is_elf64() ? 16 : 8) * (2 + 3)); rptr = rbuf; for (i = 0; i < numfiles; i++) @@ -3293,7 +3293,7 @@ static void dwarf_findfile(const char * fname) } /* add file name to end of list */ - dwarf_clist = (struct linelist *)nasm_malloc(sizeof(struct linelist)); + dwarf_clist = nasm_malloc(sizeof(struct linelist)); dwarf_numfiles++; dwarf_clist->line = dwarf_numfiles; dwarf_clist->filename = nasm_malloc(strlen(fname) + 1); @@ -3332,7 +3332,7 @@ static void dwarf_findsect(const int index) } /* add entry to end of list */ - dwarf_csect = (struct sectlist *)nasm_malloc(sizeof(struct sectlist)); + dwarf_csect = nasm_malloc(sizeof(struct sectlist)); dwarf_nsections++; dwarf_csect->psaa = plinep = saa_init(1L); dwarf_csect->line = 1; |