diff --git a/rts/linker/PEi386.c b/rts/linker/PEi386.c index c30957b75098537d23f6bb536f394ff001ea3e05..4ede63c1d35c279aa28f1883d90e1e77135b4693 100644 --- a/rts/linker/PEi386.c +++ b/rts/linker/PEi386.c @@ -1775,9 +1775,13 @@ ocGetNames_PEi386 ( ObjectCode* oc ) targetSection = NULL; break; default: - targetSection = &oc->sections[targetSecNumber-1]; + // targetSecNumber is a uint32_t, and the 0 case should be caught by PE_SECTION_UNDEFINED. + // The compiler should be smart enough to eliminate the guard, we'll keep it in as fail + // safe nontheless. + targetSection = targetSecNumber > 0 ? &oc->sections[targetSecNumber-1] : NULL; } - addr = (SymbolAddr*) ((size_t) targetSection->start + getSymValue(info, targetSym)); + if(NULL != targetSection) + addr = (SymbolAddr*) ((size_t) targetSection->start + getSymValue(info, targetSym)); } else if ( secNumber == IMAGE_SYM_UNDEFINED && symValue > 0) { /* This symbol isn't in any section at all, ie, global bss.