Skip to content

Commit

Permalink
Fix Accessors getters for nullable string/octstr attributes. (#32830)
Browse files Browse the repository at this point in the history
Callers have to pass a Nullable<Span> that already points to the buffer to
fill.  But we were calling SetNonNull(), which reset the Nullable to point to an
empty span, after which copying the data in of course failed.

The right thing to do is to ensure that the Nullable has a value, then use that
value.
  • Loading branch information
bzbarsky-apple authored Apr 8, 2024
1 parent bcf2a7a commit 35d3a25
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <app/util/attribute-table.h>
#include <app/util/odd-sized-integers.h>
#include <lib/core/CHIPEncoding.h>
#include <lib/support/logging/CHIPLogging.h>

namespace chip {
namespace app {
Expand All @@ -38,6 +39,13 @@ namespace {{asUpperCamelCase label}} {
Protocols::InteractionModel::Status Get(chip::EndpointId endpoint, {{accessorGetterType this}} value)
{
{{~#if (isString type)}}
{{#if isNullable}}
if (value.IsNull()) {
ChipLogError(Zcl, "Null Nullable<Span> passed to {{asUpperCamelCase parent.label}}::{{asUpperCamelCase label}}::Get");
return Protocols::InteractionModel::Status::Failure;
}

{{/if}}
{{~#*inline "lengthType"}}uint{{#if (isShortString type)}}8{{else}}16{{/if}}_t{{/inline}}
uint8_t zclString[{{maxLength}} + {{>sizingBytes}}];
Protocols::InteractionModel::Status status = emberAfReadAttribute(endpoint, {{>clusterId}}, Id, zclString, sizeof(zclString));
Expand All @@ -53,7 +61,7 @@ Protocols::InteractionModel::Status Get(chip::EndpointId endpoint, {{accessorGet
{{/if}}
}
{{#if isNullable}}
auto & span = value.SetNonNull();
auto & span = value.Value();
{{/if}}
{{~#*inline "value"}}{{#if isNullable}}span{{else}}value{{/if}}{{/inline}}
VerifyOrReturnError({{>value}}.size() == {{maxLength}}, Protocols::InteractionModel::Status::InvalidDataType);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 35d3a25

Please sign in to comment.