-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TLV reader: Fix float
support and remove union UB
#8531
Merged
bzbarsky-apple
merged 2 commits into
project-chip:master
from
anqid-g:tlv-reader-floats
Jul 30, 2021
Merged
TLV reader: Fix float
support and remove union UB
#8531
bzbarsky-apple
merged 2 commits into
project-chip:master
from
anqid-g:tlv-reader-floats
Jul 30, 2021
Conversation
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
anqid-g
force-pushed
the
tlv-reader-floats
branch
2 times, most recently
from
July 21, 2021 17:17
b90419b
to
55feaff
Compare
tcarmelveilleux
approved these changes
Jul 21, 2021
anqid-g
force-pushed
the
tlv-reader-floats
branch
2 times, most recently
from
July 21, 2021 19:17
dc5fa54
to
7b07d8f
Compare
Size increase report for "esp32-example-build" from af1cc26
Full report output
|
pullapprove
bot
requested review from
andy31415,
bzbarsky-apple,
chrisdecenzo,
Damian-Nordic,
hawk248,
jepenven-silabs and
msandstedt
July 21, 2021 21:27
bzbarsky-apple
approved these changes
Jul 21, 2021
anqid-g
changed the title
TLV reader: Fix floating support
TLV reader: Fix Jul 22, 2021
float
support
anqid-g
changed the title
TLV reader: Fix
TLV reader: Fix Jul 22, 2021
float
supportfloat
support and remove union UB
woody-apple
approved these changes
Jul 23, 2021
andy31415
approved these changes
Jul 26, 2021
anqid-g
force-pushed
the
tlv-reader-floats
branch
from
July 28, 2021 17:14
7b07d8f
to
0ae7c31
Compare
anqid-g
force-pushed
the
tlv-reader-floats
branch
from
July 28, 2021 17:18
0ae7c31
to
346038d
Compare
msandstedt
approved these changes
Jul 28, 2021
anqid-g
force-pushed
the
tlv-reader-floats
branch
from
July 28, 2021 20:34
346038d
to
68a2b7c
Compare
bzbarsky-apple
approved these changes
Jul 29, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful, thank you!
/rebase |
woody-apple
force-pushed
the
tlv-reader-floats
branch
from
July 29, 2021 18:09
403d85b
to
d37a104
Compare
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.
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.
anqid-g
force-pushed
the
tlv-reader-floats
branch
from
July 29, 2021 18:39
d37a104
to
f31add3
Compare
anqid-g
added a commit
to anqid-g/openweave-core
that referenced
this pull request
Jul 30, 2021
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. This is a backport from an analogous commit to CHIP: project-chip/connectedhomeip#8531
rcasallas-silabs
pushed a commit
to rcasallas-silabs/connectedhomeip
that referenced
this pull request
Aug 2, 2021
* 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.
anqid-g
added a commit
to anqid-g/openweave-core
that referenced
this pull request
Aug 3, 2021
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. This is a backport from an analogous commit to CHIP: project-chip/connectedhomeip#8531 GitHub commit: 7de322b Change-Id: I53828d172066d433114a2584636af54fd7dbaacd
anqid-g
added a commit
to anqid-g/openweave-core
that referenced
this pull request
Aug 3, 2021
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. This is a backport from an analogous commit to CHIP: project-chip/connectedhomeip#8531
nikita-s-wrk
pushed a commit
to nikita-s-wrk/connectedhomeip
that referenced
this pull request
Sep 23, 2021
* 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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
but never defined. Define it as well, extracting a helper function
for both Get(float&) and Get(double&).
raw memcpy calls instead, which is well-defined (std::bit_cast is not
available). Compilers will generally be able to optimize this away
unless a freestanding implementation (with possibly non-standard
memcpy) is used.
Problem
Various improvements to
TLVReader
floating point code.Change overview
TLVReader::Get(float&)
memcpy
instead of type-punning for bit conversions from integer to floating-pointTesting
double