Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

TLV reader: Improve floating-point support #675

Merged
merged 1 commit into from
Aug 5, 2021

Conversation

anqid-g
Copy link
Contributor

@anqid-g anqid-g commented 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

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
@robszewczyk robszewczyk merged commit ce14ed9 into openweave:master Aug 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants