outmacho: Only test for MAX_SECT at the point sections are laid out

Exceeding MAX_SECT is not a warning, it is a fatal error.  However,
there is no point to test for it until we already process all the
sections.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
H. Peter Anvin 2016-02-16 11:42:13 -08:00
parent e1eb7b8880
commit 615ef1a6f8

View File

@ -317,14 +317,10 @@ static uint8_t get_section_fileindex_by_index(const int32_t index)
struct section *s;
uint8_t i = 1;
for (s = sects; s != NULL && i < MAX_SECT; s = s->next, ++i)
for (s = sects; s != NULL; s = s->next, ++i)
if (index == s->index)
return i;
if (i == MAX_SECT)
nasm_error(ERR_WARNING,
"too many sections (>255) - clipped by fileindex");
return NO_SECT;
}
@ -990,6 +986,11 @@ static void macho_calculate_sizes (void)
head_sizeofcmds += MACHO_SYMCMD_SIZE;
}
if (seg_nsects > MAX_SECT) {
nasm_error(ERR_FATAL, "MachO output is limited to %d sections\n",
MAX_SECT);
}
/* Create a table of sections by file index to avoid linear search */
sectstab = nasm_malloc((seg_nsects + 1) * sizeof(*sectstab));
sectstab[0] = NULL;