Scan klocwork and fix all issues in c samples that were highlighted.
Change-Id: Id018abfd380c8723842a24f20c8f781dca177458
Signed-off-by: Sakthivel Samidurai <sakthivel.samidurai@intel.com>
return OC_STACK_DELETE_TRANSACTION;
}
-OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse) {
+OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse)
+{
+ if(clientResponse == NULL)
+ {
+ OC_LOG(INFO, TAG, "The clientResponse is NULL");
+ return OC_STACK_DELETE_TRANSACTION;
+ }
if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
{
OC_LOG(INFO, TAG, "Callback Context for GET query recvd successfully");
}
- if(clientResponse)
- {
- OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
- OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
- OC_LOG_V(INFO, TAG, "JSON = %s =============> Get Response", clientResponse->resJSONPayload);
- }
+ OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
+ OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
+ OC_LOG_V(INFO, TAG, "JSON = %s =============> Get Response", clientResponse->resJSONPayload);
+
if(clientResponse->rcvdVendorSpecificHeaderOptions &&
clientResponse->numRcvdVendorSpecificHeaderOptions)
{
OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse)
{
+ if(clientResponse == NULL)
+ {
+ OC_LOG(INFO, TAG, "The clientResponse is NULL");
+ return OC_STACK_DELETE_TRANSACTION;
+ }
if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
{
OC_LOG(INFO, TAG, "Callback Context for GET query recvd successfully");
}
- if(clientResponse)
- {
- OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
- OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
- OC_LOG_V(INFO, TAG, "JSON = %s =============> Get Response",
- clientResponse->resJSONPayload);
- }
+ OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
+ OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
+ OC_LOG_V(INFO, TAG, "JSON = %s =============> Get Response",
+ clientResponse->resJSONPayload);
+
if(clientResponse->rcvdVendorSpecificHeaderOptions &&
clientResponse->numRcvdVendorSpecificHeaderOptions)
{
}
OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse) {
- if(clientResponse) {}
+ if(clientResponse == NULL)
+ {
+ OC_LOG(INFO, TAG, "The clientResponse is NULL");
+ return OC_STACK_DELETE_TRANSACTION;
+ }
if(ctx == (void*)DEFAULT_CONTEXT_VALUE) {
OC_LOG_V(INFO, TAG, "Callback Context for PUT query recvd successfully");
OC_LOG_V(INFO, TAG, "JSON = %s =============> Discovered", clientResponse->resJSONPayload);
OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse)
{
+ if(clientResponse == NULL)
+ {
+ OC_LOG(INFO, TAG, "The clientResponse is NULL");
+ return OC_STACK_DELETE_TRANSACTION;
+ }
if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
{
OC_LOG(INFO, TAG, "Callback Context for GET query recvd successfully");
}
- if(clientResponse)
- {
- OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
- OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
- OC_LOG_V(INFO, TAG, "JSON = %s =============> Get Response",
- clientResponse->resJSONPayload);
- }
+ OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
+ OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
+ OC_LOG_V(INFO, TAG, "JSON = %s =============> Get Response",
+ clientResponse->resJSONPayload);
+
if(clientResponse->rcvdVendorSpecificHeaderOptions &&
clientResponse->numRcvdVendorSpecificHeaderOptions)
{
#include "cJSON.h"
#include "ocserver.h"
+//string length of "/a/light/" + std::numeric_limits<int>::digits10 + '\0'"
+// 9 + 9 + 1 = 19
+const int URI_MAXSIZE = 19;
static int gObserveNotifyType = 3;
if (gCurrLightInstance < SAMPLE_MAX_NUM_POST_INSTANCE)
{
// Create new Light instance
- char newLightUri[15] = "/a/light/";
- sprintf (newLightUri + strlen(newLightUri), "%d", gCurrLightInstance);
+ char newLightUri[URI_MAXSIZE];
+ snprintf(newLightUri, URI_MAXSIZE, "/a/light/%d", gCurrLightInstance);
+
json = cJSON_CreateObject();
cJSON_AddStringToObject(json,"href",gResourceUri);
cJSON_AddItemToObject(json, "rep", format=cJSON_CreateObject());
OCEntityHandlerResult ProcessDeleteRequest (OCEntityHandlerRequest *ehRequest, char *payload, uint16_t maxPayloadSize)
{
+ if(ehRequest == NULL)
+ {
+ OC_LOG(INFO, TAG, "The ehRequest is NULL");
+ return OC_EH_ERROR;
+ }
OCEntityHandlerResult ehResult = OC_EH_OK;
OC_LOG_V(INFO, TAG, "\n\nExecuting %s for resource %d ", __func__, ehRequest->resource);
uint8_t numNotifies = (SAMPLE_MAX_NUM_OBSERVATIONS)/2;
OCObservationId obsNotify[numNotifies];
- while (1)
+ while (!gQuitFlag)
{
sleep(10);
Light.power += 5;
#include "cJSON.h"
#include "ocserverbasicops.h"
+//string length of "/a/led/" + std::numeric_limits<int>::digits10 + '\0'"
+// 7 + 9 + 1 = 17
+const int URI_MAXSIZE = 17;
+
volatile sig_atomic_t gQuitFlag = 0;
static LEDResource LED;
if (gCurrLedInstance < SAMPLE_MAX_NUM_POST_INSTANCE)
{
// Create new LED instance
- char newLedUri[15] = "/a/led/";
- sprintf (newLedUri + strlen(newLedUri), "%d", gCurrLedInstance);
+ char newLedUri[URI_MAXSIZE ];
+ snprintf(newLedUri, URI_MAXSIZE, "/a/led/%d", gCurrLedInstance);
json = cJSON_CreateObject();
(void)param;
OCStackResult result = OC_STACK_ERROR;
- while (1)
+ while (!gQuitFlag)
{
sleep(10);
light.power += 5;
if (gLightUnderObservation)
{
- OC_LOG_V(INFO, TAG, " =====> Notifying stack of new power level %d\n", light.power);
+ OC_LOG_V(INFO, TAG,
+ " =====> Notifying stack of new power level %d\n", light.power);
result = OCNotifyAllObservers (light.handle, OC_NA_QOS);
if (OC_STACK_NO_OBSERVERS == result)
{
res = OCBindResource(room, fan);
OC_LOG_V(INFO, TAG, "OC Bind Contained Resource to resource: %s", getResult(res));
}
-
-