diff options
author | Campbell Barton <campbell@blender.org> | 2022-02-08 04:06:37 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-02-08 14:52:46 +0300 |
commit | 5d9d2565d2e493d3dd3e6a759297458e4d8dd263 (patch) | |
tree | 2e4c813c951dd5e454c8bf8acbcb792d7d55ace7 /source/blender | |
parent | 460d1a4cb36a6ae222721a9721c627292fdd77ec (diff) |
Cleanup: simplify DNA genfile casting
Avoid using the uint64_t as an intermediate cast since it complicates
behavior for signed types (which first need to be cast to an int64_t).
Assign both old_value_i & old_value_f from the original value to avoid
the need for different handling of signed/unsigned types.
Reviewed By: JacquesLucke
Ref D14039
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/makesdna/intern/dna_genfile.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c index 9a71e516389..0edc9b8fd9f 100644 --- a/source/blender/makesdna/intern/dna_genfile.c +++ b/source/blender/makesdna/intern/dna_genfile.c @@ -734,8 +734,7 @@ static void cast_primitive_type(const eSDNA_Type old_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. */ + * Casting back to a signed value preserves the sign (when the new value is signed). */ uint64_t old_value_i = 0; for (int a = 0; a < array_len; a++) { @@ -743,61 +742,63 @@ static void cast_primitive_type(const eSDNA_Type old_type, case SDNA_TYPE_CHAR: { const char value = *old_data; old_value_i = value; - old_value_f = (double)old_value_i; + old_value_f = (double)value; break; } case SDNA_TYPE_UCHAR: { const uchar value = *((uchar *)old_data); old_value_i = value; - old_value_f = (double)old_value_i; + old_value_f = (double)value; break; } case SDNA_TYPE_SHORT: { const short value = *((short *)old_data); old_value_i = value; - old_value_f = (double)(int64_t)old_value_i; + old_value_f = (double)value; break; } case SDNA_TYPE_USHORT: { const ushort value = *((unsigned short *)old_data); old_value_i = value; - old_value_f = (double)old_value_i; + old_value_f = (double)value; break; } case SDNA_TYPE_INT: { const int value = *((int *)old_data); old_value_i = value; - old_value_f = (double)(int64_t)old_value_i; + old_value_f = (double)value; break; } case SDNA_TYPE_FLOAT: { const float value = *((float *)old_data); + /* `int64_t` range stored in a `uint64_t`. */ + old_value_i = (uint64_t)(int64_t)value; old_value_f = value; - old_value_i = (uint64_t)(int64_t)old_value_f; break; } case SDNA_TYPE_DOUBLE: { const double value = *((double *)old_data); + /* `int64_t` range stored in a `uint64_t`. */ + old_value_i = (uint64_t)(int64_t)value; old_value_f = value; - old_value_i = (uint64_t)(int64_t)old_value_f; break; } case SDNA_TYPE_INT64: { const int64_t value = *((int64_t *)old_data); old_value_i = (uint64_t)value; - old_value_f = (double)(int64_t)old_value_i; + old_value_f = (double)value; break; } case SDNA_TYPE_UINT64: { const uint64_t value = *((uint64_t *)old_data); old_value_i = value; - old_value_f = (double)old_value_i; + old_value_f = (double)value; break; } case SDNA_TYPE_INT8: { const int8_t value = *((int8_t *)old_data); old_value_i = (uint64_t)value; - old_value_f = (double)(int64_t)old_value_i; + old_value_f = (double)value; } } |