Commit 3a406cd3 authored by Thiago Macieira's avatar Thiago Macieira Committed by Phil Coval

Fix issues dealing with OOM checking in CBOR

Since we're doing err |=, the correct way to check for OOM is with &.

TinyCBOR 0.5 is capable of reporting if you added too many or too few
elements to a container. So don't skip adding one: always add them all,
so we can get the actual size you need.

Change-Id: I56b444f9d6274221a3b7fffd150d4c8e2cb6618a
Signed-off-by: default avatarThiago Macieira <thiago.macieira@intel.com>
parent a85e1e8d
......@@ -46,7 +46,7 @@ extern "C"
* Macro to verify the validity of cbor operation.
*/
#define VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(log_tag, err, log_message) \
if ((CborNoError != (err)) && (CborErrorOutOfMemory != (err))) \
if ((CborNoError != (err)) && !(CborErrorOutOfMemory & (err))) \
{ \
if ((log_tag) && (log_message)) \
{ \
......@@ -64,7 +64,7 @@ extern "C"
} \
#define VERIFY_CBOR_NOT_OUTOFMEMORY(log_tag, err, log_message) \
if (CborErrorOutOfMemory == (err)) \
if (CborErrorOutOfMemory & (err)) \
{ \
if ((log_tag) && (log_message)) \
{ \
......
......@@ -114,7 +114,7 @@ OCStackResult OCConvertPayload(OCPayload* payload, OCPayloadFormat format,
VERIFY_PARAM_NON_NULL(TAG, out, "Failed to allocate payload");
err = OCConvertPayloadHelper(payload, format, out, &curSize);
if (CborErrorOutOfMemory != err)
if ((CborErrorOutOfMemory & err) == 0)
{
break;
}
......@@ -175,7 +175,7 @@ static int64_t OCConvertPayloadHelper(OCPayload* payload, OCPayloadFormat format
static int64_t checkError(int64_t err, CborEncoder* encoder, uint8_t* outPayload, size_t* size)
{
if (err == CborErrorOutOfMemory)
if (err & CborErrorOutOfMemory)
{
*size += cbor_encoder_get_extra_bytes_needed(encoder);
return err;
......@@ -1053,7 +1053,7 @@ static int64_t AddTextStringToMap(CborEncoder* map, const char* key, size_t keyl
return CborErrorInvalidUtf8TextString;
}
int64_t err = cbor_encode_text_string(map, key, keylen);
if (CborNoError != err)
if (CborNoError != err && CborErrorOutOfMemory != err)
{
return err;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment