Skip to content

Commit

Permalink
Add checks for a nominalPower having a value and get slotIndex check …
Browse files Browse the repository at this point in the history
…correct
  • Loading branch information
PeterC1965 committed Aug 19, 2024
1 parent a71bb17 commit d96208c
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ void Instance::HandleModifyForecastRequest(HandlerContext & ctx, const Commands:
const Structs::SlotAdjustmentStruct::Type & slotAdjustment = iterator.GetValue();

// Check for an invalid slotIndex
if (slotAdjustment.slotIndex > forecast.Value().slots.size())
if (slotAdjustment.slotIndex >= forecast.Value().slots.size())
{
ChipLogError(Zcl, "DEM: Bad slot index %d", slotAdjustment.slotIndex);
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::Failure);
Expand All @@ -696,7 +696,8 @@ void Instance::HandleModifyForecastRequest(HandlerContext & ctx, const Commands:
// NominalPower is only relevant if PFR is supported
if (HasFeature(Feature::kPowerForecastReporting))
{
if (!slot.minPowerAdjustment.HasValue() || !slot.maxPowerAdjustment.HasValue() ||
if (!slotAdjustment.nominalPower.HasValue() ||
!slot.minPowerAdjustment.HasValue() || !slot.maxPowerAdjustment.HasValue() ||
slotAdjustment.nominalPower.Value() < slot.minPowerAdjustment.Value() ||
slotAdjustment.nominalPower.Value() > slot.maxPowerAdjustment.Value())
{
Expand Down

0 comments on commit d96208c

Please sign in to comment.