diff --git a/src/mms/iso_mms/common/mms_value.c b/src/mms/iso_mms/common/mms_value.c index e0a27ee6..0d6e12c3 100644 --- a/src/mms/iso_mms/common/mms_value.c +++ b/src/mms/iso_mms/common/mms_value.c @@ -223,67 +223,76 @@ MmsValue_equalTypes(const MmsValue* self, const MmsValue* otherValue) bool MmsValue_update(MmsValue* self, const MmsValue* update) { - if (self->type == update->type) { - switch (self->type) { - case MMS_STRUCTURE: - case MMS_ARRAY: - if (updateStructuredComponent(self, update) == false) - return false; - break; - case MMS_BOOLEAN: - self->value.boolean = update->value.boolean; - break; - case MMS_FLOAT: - if (self->value.floatingPoint.formatWidth == update->value.floatingPoint.formatWidth) { - self->value.floatingPoint.exponentWidth = update->value.floatingPoint.exponentWidth; - memcpy(self->value.floatingPoint.buf, update->value.floatingPoint.buf, - self->value.floatingPoint.formatWidth / 8); - } - else return false; - break; - case MMS_INTEGER: - case MMS_UNSIGNED: - if (BerInteger_setFromBerInteger(self->value.integer, update->value.integer)) - return true; - else - return false; - break; - case MMS_UTC_TIME: - memcpy(self->value.utcTime, update->value.utcTime, 8); - break; - case MMS_BIT_STRING: - if (self->value.bitString.size == update->value.bitString.size) - memcpy(self->value.bitString.buf, update->value.bitString.buf, bitStringByteSize(self)); - else return false; - break; - case MMS_OCTET_STRING: - if (self->value.octetString.maxSize == update->value.octetString.maxSize) { - memcpy(self->value.octetString.buf, update->value.octetString.buf, - update->value.octetString.size); - - self->value.octetString.size = update->value.octetString.size; - } - else return false; - break; - case MMS_VISIBLE_STRING: - MmsValue_setVisibleString(self, update->value.visibleString.buf); - break; - case MMS_STRING: - MmsValue_setMmsString(self, update->value.visibleString.buf); - break; - case MMS_BINARY_TIME: - self->value.binaryTime.size = update->value.binaryTime.size; - memcpy(self->value.binaryTime.buf, update->value.binaryTime.buf, - update->value.binaryTime.size); - break; - default: - return false; - break; - } - return true; - } - else - return false; + if (self->type == update->type) { + switch (self->type) { + case MMS_STRUCTURE: + case MMS_ARRAY: + if (updateStructuredComponent(self, update) == false) + return false; + break; + case MMS_BOOLEAN: + self->value.boolean = update->value.boolean; + break; + case MMS_FLOAT: + if (self->value.floatingPoint.formatWidth == update->value.floatingPoint.formatWidth) { + self->value.floatingPoint.exponentWidth = update->value.floatingPoint.exponentWidth; + memcpy(self->value.floatingPoint.buf, update->value.floatingPoint.buf, + self->value.floatingPoint.formatWidth / 8); + } + else + return false; + break; + case MMS_INTEGER: + case MMS_UNSIGNED: + if (BerInteger_setFromBerInteger(self->value.integer, update->value.integer)) + return true; + else + return false; + break; + case MMS_UTC_TIME: + memcpy(self->value.utcTime, update->value.utcTime, 8); + break; + case MMS_BIT_STRING: + if (self->value.bitString.size == update->value.bitString.size) + memcpy(self->value.bitString.buf, update->value.bitString.buf, bitStringByteSize(self)); + else + return false; + break; + case MMS_OCTET_STRING: + { + int size = update->value.octetString.size; + + if (size > self->value.octetString.maxSize) { + GLOBAL_FREEMEM(self->value.octetString.buf); + self->value.octetString.buf = GLOBAL_MALLOC(size); + self->value.octetString.maxSize = size; + } + size = self->value.octetString.maxSize; + + memcpy(self->value.octetString.buf, update->value.octetString.buf, size); + + self->value.octetString.size = size; + } + break; + case MMS_VISIBLE_STRING: + MmsValue_setVisibleString(self, update->value.visibleString.buf); + break; + case MMS_STRING: + MmsValue_setMmsString(self, update->value.visibleString.buf); + break; + case MMS_BINARY_TIME: + self->value.binaryTime.size = update->value.binaryTime.size; + memcpy(self->value.binaryTime.buf, update->value.binaryTime.buf, + update->value.binaryTime.size); + break; + default: + return false; + break; + } + return true; + } + else + return false; } MmsValue*