From d9ab1897d95acb250c31c77718e67946f0e60a5d Mon Sep 17 00:00:00 2001 From: Ravi Nanjundappa Date: Fri, 3 Jul 2015 16:36:22 +0530 Subject: [PATCH] soft-sensor-manager: Fixes cppcheck issue for arduino SampleApp This patch fixes the the below issue reported by cppcheck tool in stack dir: "(error) Possible null pointer dereference: entityHandlerRequest - otherwise it is redundant to check if entityHandlerRequest is null at line 114" Dereferencing of entityHandlerRequest->resJSONPayload is done if flag includes OC_REQUEST_FLAG. The patch also includes removal of some unnecessary blank lines Change-Id: I8d9d7c40df5602b9d55de8d948871a2c485798a2 Signed-off-by: Ravi Nanjundappa Reviewed-on: https://gerrit.iotivity.org/gerrit/1510 Reviewed-by: Erich Keane Tested-by: jenkins-iotivity Reviewed-by: Minji Park Reviewed-by: Uze Choi --- .../arduino/Reference_Thing/src/trackee.cpp | 75 +++++++++------------- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/service/soft-sensor-manager/SampleApp/arduino/Reference_Thing/src/trackee.cpp b/service/soft-sensor-manager/SampleApp/arduino/Reference_Thing/src/trackee.cpp index 82780a5..253898e 100644 --- a/service/soft-sensor-manager/SampleApp/arduino/Reference_Thing/src/trackee.cpp +++ b/service/soft-sensor-manager/SampleApp/arduino/Reference_Thing/src/trackee.cpp @@ -41,8 +41,6 @@ PROGMEM const char TAG[] = "TrackeeSensor"; OCResourceHandle m_handle; - - Cble ble; char trackeeID[13] = "9059AF16FEF7"; int slaver_num = 0; @@ -50,21 +48,15 @@ int slaver_num = 0; char slaveList[SLAVER_EA][13] = {"9059AF1700EE", "34B1F7D004D2"}; int g_PROXIUnderObservation = 0; - - const char *getResult(OCStackResult result); void createResource(); - #define LENGTH_VAR 50 bool JsonGenerator( char *jsonBuf, uint16_t buf_length ) { - return true; - } - // On Arduino Atmel boards with Harvard memory architecture, the stack grows // downwards from the top and the heap grows upwards. This method will print // the distance(in terms of bytes) between those two. @@ -91,50 +83,49 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, { OCEntityHandlerResult ehRet = OC_EH_OK; - if (entityHandlerRequest && (flag & OC_REQUEST_FLAG)) + if (entityHandlerRequest ) { - OC_LOG (INFO, TAG, PCF("Flag includes OC_REQUEST_FLAG")); - if (OC_REST_GET == entityHandlerRequest->method) + if (flag & OC_REQUEST_FLAG) { - if ( JsonGenerator( (char *)entityHandlerRequest->resJSONPayload, - entityHandlerRequest->resJSONPayloadLen ) == false ) + OC_LOG (INFO, TAG, PCF("Flag includes OC_REQUEST_FLAG")); + if (OC_REST_GET == entityHandlerRequest->method) { - ehRet = OC_EH_ERROR; + if ( JsonGenerator( (char *)entityHandlerRequest->resJSONPayload, + entityHandlerRequest->resJSONPayloadLen ) == false ) + { + ehRet = OC_EH_ERROR; + } } - } - if (OC_REST_PUT == entityHandlerRequest->method) - { - if (JsonGenerator( (char *)entityHandlerRequest->resJSONPayload, - entityHandlerRequest->resJSONPayloadLen ) == false ) + if (OC_REST_PUT == entityHandlerRequest->method) { - ehRet = OC_EH_ERROR; + if (JsonGenerator( (char *)entityHandlerRequest->resJSONPayload, + entityHandlerRequest->resJSONPayloadLen ) == false ) + { + ehRet = OC_EH_ERROR; + } } + } - } - else if (entityHandlerRequest && (flag & OC_OBSERVE_FLAG)) - { - if (OC_OBSERVE_REGISTER == entityHandlerRequest->obsInfo->action) - { - OC_LOG (INFO, TAG, PCF("Received OC_OBSERVE_REGISTER from client")); - g_PROXIUnderObservation = 1; - } - else if (OC_OBSERVE_DEREGISTER == entityHandlerRequest->obsInfo->action) + else if (flag & OC_OBSERVE_FLAG) { - OC_LOG (INFO, TAG, PCF("Received OC_OBSERVE_DEREGISTER from client")); + OC_LOG (INFO, TAG, PCF("Flag includes OC_OBSERVE_FLAG")); + if (OC_OBSERVE_REGISTER == entityHandlerRequest->obsInfo->action) + { + OC_LOG (INFO, TAG, PCF("Received OC_OBSERVE_REGISTER from client")); + g_PROXIUnderObservation = 1; + } + else if (OC_OBSERVE_DEREGISTER == entityHandlerRequest->obsInfo->action) + { + OC_LOG (INFO, TAG, PCF("Received OC_OBSERVE_DEREGISTER from client")); + } } - } - Serial.println((char *)entityHandlerRequest->resJSONPayload); + Serial.println((char *)entityHandlerRequest->resJSONPayload); + } return ehRet; } - - - - - - //The setup function is called once at startup of the sketch void setup() { @@ -168,7 +159,6 @@ void setup() ble.init( (long)115200, BLE_SLAVER, slaveList[0]); - // ble.StatusRead(); OC_LOG_V(INFO, TAG, "Program Start-\r\n"); @@ -180,7 +170,6 @@ void loop() { // This artificial delay is kept here to avoid endless spinning // of Arduino microcontroller. Modify it as per specfic application needs. - if (OCProcess() != OC_STACK_OK) { OC_LOG(ERROR, TAG, PCF("OCStack process error")); @@ -202,12 +191,6 @@ void loop() } - - - - - - void createResource() { -- 2.7.4