Fix getPaymentMethodId(): check for valid iterator.

This commit is contained in:
Gerhard Hoffmann 2024-01-31 15:09:42 +01:00
parent 9438a535ea
commit 25a39fdc61

View File

@ -354,22 +354,24 @@ bool Utilities::isCarryOverNotSet(Configuration const *cfg, PaymentMethod paymen
} }
PaymentMethod Utilities::getPaymentMethodId(Configuration const *cfg) { PaymentMethod Utilities::getPaymentMethodId(Configuration const *cfg) {
if (cfg->PaymentOption.size() != 1) { if (cfg->PaymentOption.size() == 0) {
return PaymentMethod::Undefined; return PaymentMethod::Undefined;
} }
std::multimap<int, ATBPaymentOption>::const_iterator it = std::multimap<int, ATBPaymentOption>::const_iterator it =
cfg->PaymentOption.cbegin(); cfg->PaymentOption.cbegin();
switch (it->first) { if (it != cfg->PaymentOption.cend()) {
case PaymentMethod::Linear: switch (it->first) {
return PaymentMethod::Linear; case PaymentMethod::Linear:
case PaymentMethod::Steps: return PaymentMethod::Linear;
return PaymentMethod::Steps; case PaymentMethod::Steps:
case PaymentMethod::Degressive: return PaymentMethod::Steps;
return PaymentMethod::Degressive; case PaymentMethod::Degressive:
case PaymentMethod::Progressive: return PaymentMethod::Degressive;
return PaymentMethod::Progressive; case PaymentMethod::Progressive:
return PaymentMethod::Progressive;
}
} }
return PaymentMethod::Undefined; return PaymentMethod::Undefined;