-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TLV reader: Fix
float
support and remove union UB (#8531)
* TLV reader: Improve floating-point support 1. For some reason the Get(float&) signature was declared in the .h file but was never defined. Define it as well. Disallow reading a 64-bit floating point number to float, to avoid silent truncation / loss of precision. 2. It is undefined behaviour to use unions for type-punning in C++. Use raw memcpy calls instead, which is defined by the C++ standard (std::bit_cast is not available). Compilers will generally be able to optimize this memcpy away, unless a freestanding implementation (with possibly non-standard memcpy) is used. * TLV writer: Remove union UB It is undefined behaviour to use unions for type-punning in C++. Use raw memcpy calls instead, as a substitute for the unavailable std::bit_cast.
- Loading branch information
Showing
3 changed files
with
85 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters