Skip to content

Commit

Permalink
Update a nullable check to make use of ValueToNullValue
Browse files Browse the repository at this point in the history
  • Loading branch information
andy31415 committed Oct 23, 2024
1 parent e0811b7 commit f80cf68
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/app/codegen-data-model-provider/EmberDataBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,13 @@ CHIP_ERROR EmberAttributeBuffer::DecodeUnsignedInteger(chip::TLV::TLVReader & re
{
ReturnErrorOnFailure(reader.Get(value));

VerifyOrReturnError(mIsNullable // ::max() on the type is used as the NULL flag
? (value < info.maxValue)
: (value <= info.maxValue),
CHIP_IM_GLOBAL_STATUS(ConstraintError));
bool valid =
// Value is in [0, max] RANGE
(value <= info.maxValue)
// Nullable values reserve a specific value to mean NULL
&& !(mIsNullable && (value == NumericLimits::UnsignedMaxValueToNullValue(info.maxValue)));

VerifyOrReturnError(valid, CHIP_IM_GLOBAL_STATUS(ConstraintError));
}

writer.EndianPut(value, info.byteCount);
Expand All @@ -186,10 +189,11 @@ CHIP_ERROR EmberAttributeBuffer::DecodeSignedInteger(chip::TLV::TLVReader & read
{
ReturnErrorOnFailure(reader.Get(value));

// NULLABLE reserves minValue for NULL, so range is:
// - NULLABLE: (minValue, MaxValue]
// - NON-NULLABLE: [minValue, MaxValue]
bool valid = (value <= info.maxValue) && (mIsNullable ? (value > info.minValue) : (value >= info.minValue));
bool valid =
// Value is in [min, max] RANGE
((value >= info.minValue) && (value <= info.maxValue))
// Nullable values reserve a specific value to mean NULL
&& !(mIsNullable && (value == SignedMinValueToNullValue(info.minValue)));

VerifyOrReturnError(valid, CHIP_IM_GLOBAL_STATUS(ConstraintError));
}
Expand Down

0 comments on commit f80cf68

Please sign in to comment.