Skip to content

Commit ee78c59

Browse files
Fix Accessors getters for nullable string/octstr attributes.
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.
1 parent 0c0c6d6 commit ee78c59

File tree

2 files changed

+66
-9
lines changed

2 files changed

+66
-9
lines changed

src/app/zap-templates/templates/app/attributes/Accessors-src.zapt

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <app/util/attribute-storage-null-handling.h>
1515
#include <app/util/odd-sized-integers.h>
1616
#include <lib/core/CHIPEncoding.h>
17+
#include <lib/support/logging/CHIPLogging.h>
1718

1819
namespace chip {
1920
namespace app {
@@ -38,6 +39,13 @@ namespace {{asUpperCamelCase label}} {
3839
Protocols::InteractionModel::Status Get(chip::EndpointId endpoint, {{accessorGetterType this}} value)
3940
{
4041
{{~#if (isString type)}}
42+
{{#if isNullable}}
43+
if (value.IsNull()) {
44+
ChipLogError(Zcl, "Null Nullable<Span> passed to {{asUpperCamelCase parent.label}}::{{asUpperCamelCase label}}::Get");
45+
return Protocols::InteractionModel::Status::Failure;
46+
}
47+
48+
{{/if}}
4149
{{~#*inline "lengthType"}}uint{{#if (isShortString type)}}8{{else}}16{{/if}}_t{{/inline}}
4250
uint8_t zclString[{{maxLength}} + {{>sizingBytes}}];
4351
Protocols::InteractionModel::Status status = emberAfReadAttribute(endpoint, {{>clusterId}}, Id, zclString, sizeof(zclString));
@@ -53,7 +61,7 @@ Protocols::InteractionModel::Status Get(chip::EndpointId endpoint, {{accessorGet
5361
{{/if}}
5462
}
5563
{{#if isNullable}}
56-
auto & span = value.SetNonNull();
64+
auto & span = value.Value();
5765
{{/if}}
5866
{{~#*inline "value"}}{{#if isNullable}}span{{else}}value{{/if}}{{/inline}}
5967
VerifyOrReturnError({{>value}}.size() == {{maxLength}}, Protocols::InteractionModel::Status::InvalidDataType);

zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp

+57-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)