From 48845779db6e1df6c233b7ad5a72f8667737de14 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 6 Apr 2023 14:08:28 -0400 Subject: [PATCH] Fix example bridge reads of integer attributes of size > 1 byte. (#25965) The code that was there only read one byte from the value. --- examples/bridge-app/esp32/main/main.cpp | 6 ++++-- examples/bridge-app/linux/main.cpp | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/examples/bridge-app/esp32/main/main.cpp b/examples/bridge-app/esp32/main/main.cpp index f79f80f8bd5c8a..f0762ef631749b 100644 --- a/examples/bridge-app/esp32/main/main.cpp +++ b/examples/bridge-app/esp32/main/main.cpp @@ -230,7 +230,8 @@ EmberAfStatus HandleReadBridgedDeviceBasicAttribute(Device * dev, chip::Attribut } else if ((attributeId == ClusterRevision::Id) && (maxReadLength == 2)) { - *buffer = (uint16_t) ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION; + uint16_t rev = ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION; + memcpy(buffer, &rev, sizeof(rev)); } else { @@ -250,7 +251,8 @@ EmberAfStatus HandleReadOnOffAttribute(Device * dev, chip::AttributeId attribute } else if ((attributeId == OnOff::Attributes::ClusterRevision::Id) && (maxReadLength == 2)) { - *buffer = (uint16_t) ZCL_ON_OFF_CLUSTER_REVISION; + uint16_t rev = ZCL_ON_OFF_CLUSTER_REVISION; + memcpy(buffer, &rev, sizeof(rev)); } else { diff --git a/examples/bridge-app/linux/main.cpp b/examples/bridge-app/linux/main.cpp index 3fae757c736ff8..314036a83c5dcd 100644 --- a/examples/bridge-app/linux/main.cpp +++ b/examples/bridge-app/linux/main.cpp @@ -500,11 +500,13 @@ EmberAfStatus HandleReadBridgedDeviceBasicAttribute(Device * dev, chip::Attribut } else if ((attributeId == ClusterRevision::Id) && (maxReadLength == 2)) { - *buffer = (uint16_t) ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION; + uint16_t rev = ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION; + memcpy(buffer, &rev, sizeof(rev)); } else if ((attributeId == FeatureMap::Id) && (maxReadLength == 4)) { - *buffer = (uint32_t) ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_FEATURE_MAP; + uint32_t featureMap = ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_FEATURE_MAP; + memcpy(buffer, &featureMap, sizeof(featureMap)); } else { @@ -524,7 +526,8 @@ EmberAfStatus HandleReadOnOffAttribute(DeviceOnOff * dev, chip::AttributeId attr } else if ((attributeId == OnOff::Attributes::ClusterRevision::Id) && (maxReadLength == 2)) { - *buffer = (uint16_t) ZCL_ON_OFF_CLUSTER_REVISION; + uint16_t rev = ZCL_ON_OFF_CLUSTER_REVISION; + memcpy(buffer, &rev, sizeof(rev)); } else {