Skip to content

Commit

Permalink
fix: compiler warning: dereferencing type-punned pointer will break s…
Browse files Browse the repository at this point in the history
…trict-aliasing rules
  • Loading branch information
devmirek committed Apr 3, 2024
1 parent b13baf8 commit b31bb3b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ double TheengsDecoder::value_from_hex_string(const char* data_str,
value = strtoll(data.c_str(), NULL, 16);
DEBUG_PRINT("extracted value from %s = %lld\n", data.c_str(), (long long)value);
} else {
long longV = strtol(data.c_str(), NULL, 16);
float floatV = *((float*)&longV);
union {
long longV;
float floatV;
};
longV = strtol(data.c_str(), NULL, 16);
DEBUG_PRINT("extracted float value from %s = %f\n", data.c_str(), floatV);
value = floatV;
}
Expand Down

0 comments on commit b31bb3b

Please sign in to comment.