C++ Avoid crash in case of Invalid/Empty Payload
authoromkar <omkar.m.hegde@intel.com>
Fri, 9 Jan 2015 19:34:18 +0000 (11:34 -0800)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Thu, 22 Jan 2015 15:34:31 +0000 (15:34 +0000)
This change is based on a bug reported by SHP wherein
they want to be able to send response with empty payload.
Instead of throwing an error, we now send an empty
OCRepresentation() object to the client callback.

Change-Id: I16f298bf8a0bdbb545e1133d751582f418991352
Signed-off-by: omkar <omkar.m.hegde@intel.com>
(cherry picked from commit 43e5a4f0a42a739e93f65ccf31eff82df11144c3)
Reviewed-on: https://gerrit.iotivity.org/gerrit/212
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
resource/src/InProcClientWrapper.cpp

index 4d4558c..6ecaaf4 100644 (file)
@@ -96,7 +96,7 @@ namespace OC
     {
         if(clientResponse->resJSONPayload == nullptr || clientResponse->resJSONPayload[0] == '\0')
         {
-            throw OCException(OC::Exception::STR_NULL_RESPONSE, OC_STACK_ERROR);
+            return OCRepresentation();
         }
 
         MessageContainer oc;
@@ -105,7 +105,7 @@ namespace OC
         std::vector<OCRepresentation>::const_iterator it = oc.representations().begin();
         if(it == oc.representations().end())
         {
-            throw OCException(OC::Exception::INVALID_REPRESENTATION, OC_STACK_ERROR);
+            return OCRepresentation();
         }
 
         // first one is considered the root, everything else is considered a child of this one.