Fix access to undefined SlotCount.

This commit is contained in:
jief666 2021-10-17 13:20:36 +02:00
parent dfbdc8ae45
commit 8b14c24c7c

View File

@ -207,9 +207,17 @@ public:
virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override { virtual XBool validate(XmlLiteParser* xmlLiteParser, const XString8& xmlPath, const XmlParserPosition& keyPos, XBool generateErrors) override {
if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false; if ( !super::validate(xmlLiteParser, xmlPath, keyPos, generateErrors) ) return false;
XBool b = true; XBool b = true;
if ( Modules.size() == 0 ) {
// whatever if SlotCount is defined or not, and whatever value, it's ok.
return b;
}
if ( !SlotCount.isDefined() ) {
xmlLiteParser->addWarning(generateErrors, S8Printf("SlotCount is not defined in SMBIOS, but you defined memory modules. SlotCount adjusted to %d, which maybe wrong.", Modules.dgetCalculatedSlotCount())); // do not set b to false because value is auto-corrected, so it's now ok.
SlotCount.setUInt8Value(Modules.dgetCalculatedSlotCount());
}else{
for ( size_t i = 0 ; i < Modules.size() ; ) { for ( size_t i = 0 ; i < Modules.size() ; ) {
if ( Modules[i].SlotIndex.value() >= SlotCount.value() ) { if ( Modules[i].SlotIndex.value() >= SlotCount.value() ) {
xmlLiteParser->addWarning(generateErrors, S8Printf("Ignore memory module with slot >= SlotCount at '%s:%d'", xmlPath.c_str(), keyPos.getLine())); xmlLiteParser->addWarning(generateErrors, S8Printf("Ignored memory module with slot >= SlotCount at '%s:%d'", xmlPath.c_str(), keyPos.getLine())); // do not set b to false because value is auto-corrected, so it's now ok.
Modules.RemoveAtIndex(i); Modules.RemoveAtIndex(i);
}else{ }else{
i++; i++;
@ -219,6 +227,7 @@ public:
log_technical_bug("SlotCount.value() < Modules.dgetCalculatedSlotCount()"); log_technical_bug("SlotCount.value() < Modules.dgetCalculatedSlotCount()");
SlotCount.setUInt8Value(Modules.dgetCalculatedSlotCount()); SlotCount.setUInt8Value(Modules.dgetCalculatedSlotCount());
} }
}
return b; return b;
} }