Commits

Anonymous committed 4c01c66

fixed FreeImage_CloneTag behavior with ASCII data handling (regression that appeared in 3.15.2, affect metadata writing)

Comments (0)

Files changed (1)

Source/Metadata/FreeImageTag.cpp

 		// tag length
 		dst_tag->length = src_tag->length;
 		// tag value
-		dst_tag->value = (BYTE*)malloc(src_tag->length * sizeof(BYTE));
-		if(!dst_tag->value) {
-			throw FI_MSG_ERROR_MEMORY;
+		switch(dst_tag->type) {
+			case FIDT_ASCII:
+				dst_tag->value = (BYTE*)malloc((src_tag->length + 1) * sizeof(BYTE));
+				if(!dst_tag->value) {
+					throw FI_MSG_ERROR_MEMORY;
+				}
+				memcpy(dst_tag->value, src_tag->value, src_tag->length);
+				((BYTE*)dst_tag->value)[src_tag->length] = 0;
+				break;
+			default:
+				dst_tag->value = (BYTE*)malloc(src_tag->length * sizeof(BYTE));
+				if(!dst_tag->value) {
+					throw FI_MSG_ERROR_MEMORY;
+				}
+				memcpy(dst_tag->value, src_tag->value, src_tag->length);
+				break;
 		}
-		memcpy(dst_tag->value, src_tag->value, src_tag->length);
 
 		return clone;