Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-02-08 03:50:15 +0300
committerCampbell Barton <campbell@blender.org>2022-02-08 03:54:44 +0300
commit9d674d9852db07ade16b521d1c0864b494d232e5 (patch)
tree633532c9dfea1ca06029a3a6bcd9faf8b725f4cf /source
parent7df651367fbd8c9510c7e02b18301bd2f28c3574 (diff)
Fix dna_genfile error converting signed int types to floating point
Regression in 51befa4108128a7bacf7a201046cf7ede999833a caused negative values to overflow into a uint64_t. Resolve by casting to a signed int from originally signed types. This caused D14033 not to work properly.
Diffstat (limited to 'source')
-rw-r--r--source/blender/makesdna/intern/dna_genfile.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c
index 7e9fabcc998..9a71e516389 100644
--- a/source/blender/makesdna/intern/dna_genfile.c
+++ b/source/blender/makesdna/intern/dna_genfile.c
@@ -733,6 +733,9 @@ static void cast_primitive_type(const eSDNA_Type old_type,
const int curlen = DNA_elem_type_size(new_type);
double old_value_f = 0.0;
+ /* Intentionally overflow signed values into an unsigned type.
+ * Casting back to a signed value preserves the sign (when the new value is signed).
+ * It's also important to cast to `int64_t` when setting `old_value_f` from a signed value. */
uint64_t old_value_i = 0;
for (int a = 0; a < array_len; a++) {
@@ -752,7 +755,7 @@ static void cast_primitive_type(const eSDNA_Type old_type,
case SDNA_TYPE_SHORT: {
const short value = *((short *)old_data);
old_value_i = value;
- old_value_f = (double)old_value_i;
+ old_value_f = (double)(int64_t)old_value_i;
break;
}
case SDNA_TYPE_USHORT: {
@@ -764,7 +767,7 @@ static void cast_primitive_type(const eSDNA_Type old_type,
case SDNA_TYPE_INT: {
const int value = *((int *)old_data);
old_value_i = value;
- old_value_f = (double)old_value_i;
+ old_value_f = (double)(int64_t)old_value_i;
break;
}
case SDNA_TYPE_FLOAT: {
@@ -782,7 +785,7 @@ static void cast_primitive_type(const eSDNA_Type old_type,
case SDNA_TYPE_INT64: {
const int64_t value = *((int64_t *)old_data);
old_value_i = (uint64_t)value;
- old_value_f = (double)old_value_i;
+ old_value_f = (double)(int64_t)old_value_i;
break;
}
case SDNA_TYPE_UINT64: {
@@ -794,7 +797,7 @@ static void cast_primitive_type(const eSDNA_Type old_type,
case SDNA_TYPE_INT8: {
const int8_t value = *((int8_t *)old_data);
old_value_i = (uint64_t)value;
- old_value_f = (double)old_value_i;
+ old_value_f = (double)(int64_t)old_value_i;
}
}