The function GetResourceFromHandle was returning a PIResource**. When
the actual code was inspected it was returning a PIResourceBase** that
was being cast to a PIResource**. That value was then used as a
PIResource**. The only reason this code worked is because the way C
lays out structs in memory is sequential Since the first element of the
PIResoruceBase is a PIResource treating the the PIResourceBase like
a PIResource worked only by virtue of the memory layout rules for C
structs.
Later in the zigbee_wapper.c it relies again on the memory layout
rules for structs to assign PIResource** to a PIResource_Zigbee**.
This relies too much on internal knowledge of memory layout and is
a potential management problem. The code tied 3 structs together
based on there memory layout.
To fix the issue. The GetResourceFromHandle now returns PIResourceBase**
which was the actual type returned. In the cleanup code the pointer
is change from PIResource* to PIResourceBase*. Now when the value is
passed into the DeleteResource function it no longer generates the
incompatible-pointer-types warning.
In zigbee_wrapper.c we no longer cast the PIResource_Zigbee* to
PIResource* we now pass in the part of the PIResource_Zigbee that is
actually the PIResourceBase.
Bug: https://jira.iotivity.org/browse/IOT-2539
Change-Id: I6b147a52c522d036d016e2cd15e2900e6fc06249
Signed-off-by: George Nash <george.nash@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/21927
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Mats Wichmann <mats@linux.com>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: Larry Sachs <larry.j.sachs@intel.com>
Reviewed-by: Rick Bell <richard.s.bell@intel.com>
(cherry picked from commit
25898d822bea23ec7f19b6858026de493031c70e)
OCStackResult DeletePluginList();
-OCStackResult GetResourceFromHandle(PIPluginBase * plugin, PIResource ** piResource,
+OCStackResult GetResourceFromHandle(PIPluginBase * plugin, PIResourceBase ** piResourceBase,
OCResourceHandle * resourceHandle);
OCStackResult GetResourceFromZigBeeNodeId(PIPluginBase * plugin,
- PIResource_Zigbee ** piResource,
+ PIResource_Zigbee ** piResourceBase,
const char * nodeId,
const char * endpointId,
const char * clusterId);
else
{
OIC_LOG_V(ERROR, TAG, "Error handling request %u", ehResult);
- PIResource * piResource = NULL;
- result = GetResourceFromHandle(plugin, &piResource, response->resourceHandle);
- OIC_LOG_V(ERROR, TAG, "Deleting resource \"%s\" because of failed request.", piResource->uri);
- result = DeleteResource(plugin, piResource);
+ PIResourceBase * piResourceBase = NULL;
+ result = GetResourceFromHandle(plugin, &piResourceBase, response->resourceHandle);
+ OIC_LOG_V(ERROR, TAG, "Deleting resource \"%s\" because of failed request.", piResourceBase->piResource.uri);
+ result = DeleteResource(plugin, piResourceBase);
if(result != OC_STACK_OK)
{
OIC_LOG_V(ERROR, TAG, "Failed to delete resource after failed request.");
return result;
}
-OCStackResult GetResourceFromHandle(PIPluginBase * plugin, PIResource ** piResource,
+OCStackResult GetResourceFromHandle(PIPluginBase * plugin, PIResourceBase **piResourceBase,
OCResourceHandle * resourceHandle)
{
- if (!plugin || !resourceHandle || !piResource)
+ if (!plugin || !resourceHandle || !piResourceBase)
{
return OC_STACK_INVALID_PARAM;
}
{
if (out->piResource.resourceHandle == resourceHandle)
{
- *piResource = (PIResource *) out;
+ *piResourceBase = out;
return OC_STACK_OK;
}
}
uint32_t attributeListIndex = 0;
OCStackResult stackResult = OC_STACK_OK;
PIResource_Zigbee * piResource = NULL;
+ PIResourceBase * piResourceBase = &piResource->header;
AttributeList attributeList = { 0, (CIECommandMask) 0,
.list[0] = { NULL, NULL, OIC_ATTR_NULL, ZB_NULL, { .i = 0 } } };
- stackResult = GetResourceFromHandle(plugin, (PIResource**) (&piResource),
+ stackResult = GetResourceFromHandle(plugin, &piResourceBase,
ehRequest->resource);
if (stackResult != OC_STACK_OK)
{
}
OCStackResult stackResult = OC_STACK_OK;
PIResource_Zigbee *piResource = NULL;
+ PIResourceBase * piResourceBase = &piResource->header;
AttributeList attributeList = {
0,
(CIECommandMask) 0,
};
stackResult = GetResourceFromHandle(plugin,
- ((PIResource **) (&piResource)),
+ &piResourceBase,
ehRequest->resource);
if (stackResult != OC_STACK_OK)
{