/**
* This function copies contents (and allocates if necessary)
- * @param dest existing bytestring (or null to allocate here)
+ * @param dest existing bytestring. The existing contents will be OICFree()'d.
* @param source existing bytestring
* @return true of success false on any errors
**/
}
break;
case OCREP_PROP_BYTE_STRING:
- dest->arr.ocByteStrArray = (OCByteString*)OICMalloc(dimTotal * sizeof(OCByteString));
+ dest->arr.ocByteStrArray = (OCByteString*)OICCalloc(dimTotal, sizeof(OCByteString));
VERIFY_PARAM_NON_NULL(TAG, dest->arr.ocByteStrArray, "Failed allocating memory");
for (size_t i = 0; i < dimTotal; ++i)
{
bool OC_CALL OCByteStringCopy(OCByteString* dest, const OCByteString* source)
{
- VERIFY_PARAM_NON_NULL(TAG, source, "Bad input");
+ VERIFY_PARAM_NON_NULL(TAG, dest, "Bad dest");
+ VERIFY_PARAM_NON_NULL(TAG, source, "Bad source");
- if (!dest)
- {
- dest = (OCByteString *)OICMalloc(sizeof(OCByteString));
- VERIFY_PARAM_NON_NULL(TAG, dest, "Failed allocating memory");
- }
if (dest->bytes)
{
OICFree(dest->bytes);
}
break;
case OCREP_PROP_BYTE_STRING:
- dest->arr.ocByteStrArray = (OCByteString*)OICMalloc(dimTotal * sizeof(OCByteString));
+ dest->arr.ocByteStrArray = (OCByteString*)OICCalloc(dimTotal, sizeof(OCByteString));
NS_VERIFY_NOT_NULL_V(dest->arr.ocByteStrArray);
for (size_t i = 0; i < dimTotal; ++i)
{