outelf32: Use nasm_zalloc helper

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov 2011-02-28 09:40:43 +03:00
parent b4af1ac765
commit efc249d8fc

View file

@ -300,25 +300,21 @@ static int elf_make_section(char *name, int type, int flags, int align)
{ {
struct Section *s; struct Section *s;
s = nasm_malloc(sizeof(*s)); s = nasm_zalloc(sizeof(*s));
if (type != SHT_NOBITS) if (type != SHT_NOBITS)
s->data = saa_init(1L); s->data = saa_init(1L);
s->head = NULL;
s->tail = &s->head; s->tail = &s->head;
s->len = s->size = 0;
s->nrelocs = 0;
if (!strcmp(name, ".text")) if (!strcmp(name, ".text"))
s->index = def_seg; s->index = def_seg;
else else
s->index = seg_alloc(); s->index = seg_alloc();
add_sectname("", name); add_sectname("", name);
s->name = nasm_malloc(1 + strlen(name));
strcpy(s->name, name); s->name = nasm_strdup(name);
s->type = type; s->type = type;
s->flags = flags; s->flags = flags;
s->align = align; s->align = align;
s->gsyms = NULL;
if (nsects >= sectlen) if (nsects >= sectlen)
sects = nasm_realloc(sects, (sectlen += SECT_DELTA) * sizeof(*sects)); sects = nasm_realloc(sects, (sectlen += SECT_DELTA) * sizeof(*sects));
@ -606,16 +602,12 @@ static void elf_add_reloc(struct Section *sect, int32_t segment, int type)
{ {
struct Reloc *r; struct Reloc *r;
r = *sect->tail = nasm_malloc(sizeof(struct Reloc)); r = *sect->tail = nasm_zalloc(sizeof(struct Reloc));
sect->tail = &r->next; sect->tail = &r->next;
r->next = NULL;
r->address = sect->len; r->address = sect->len;
if (segment == NO_SEG) if (segment != NO_SEG) {
r->symbol = 0;
else {
int i; int i;
r->symbol = 0;
for (i = 0; i < nsects; i++) for (i = 0; i < nsects; i++)
if (segment == sects[i]->index) if (segment == sects[i]->index)
r->symbol = i + 2; r->symbol = i + 2;
@ -691,11 +683,11 @@ static int32_t elf_add_gsym_reloc(struct Section *sect,
r = *sect->tail = nasm_malloc(sizeof(struct Reloc)); r = *sect->tail = nasm_malloc(sizeof(struct Reloc));
sect->tail = &r->next; sect->tail = &r->next;
r->next = NULL;
r->address = sect->len; r->next = NULL;
r->symbol = GLOBAL_TEMP_BASE + sym->globnum; r->address = sect->len;
r->type = type; r->symbol = GLOBAL_TEMP_BASE + sym->globnum;
r->type = type;
sect->nrelocs++; sect->nrelocs++;