From 7ad24562dccca867d9ba591ac7dd242456003c5b Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 26 Jul 2009 15:29:09 -0700 Subject: BR 2827397: fix invalid C in outcoff AddExports() The construct: if (i == nsects) directive_sec = sects[coff_make_section (EXPORT_SECTION_NAME, EXPORT_SECTION_FLAGS)]; ... where coff_make_section() can change the global variable "sects" is undefined C, since there is no sequence point involved in the [] operator, and it is therefore fully permitted for the C compiler to read the sects variable first. Change this construct into two statements to enforce defined behavior; this also ends up with the code slightly simpler. Signed-off-by: H. Peter Anvin --- output/outcoff.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/output/outcoff.c b/output/outcoff.c index b27cc94e..22cb3e88 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -674,16 +674,16 @@ void AddExport(char *name) strcpy(newS->String, name); if (rvp == NULL) { int i; - for (i = 0; i < nsects; i++) + for (i = 0; i < nsects; i++) { if (!strcmp(EXPORT_SECTION_NAME, sects[i]->name)) break; + } + if (i == nsects) - directive_sec = - sects[coff_make_section - (EXPORT_SECTION_NAME, EXPORT_SECTION_FLAGS)]; - else - directive_sec = sects[i]; + i = coff_make_section(EXPORT_SECTION_NAME, EXPORT_SECTION_FLAGS); + + directive_sec = sects[i]; Exports = newS; } else { while (rvp->Next) { -- cgit v1.2.1