net: lwm2m: oma_tlv: Fix UBSAN warnings about signed integers
* Simplify the logic of the get_number() function to address the corner
cases reported by UBSAN regarding byte-swapping signed integer values.
The existing logic was actually only valid for little-endian systems,
as it expected that the bytes written from the packet buffer will be
stored at the beginning of the int64_t memory, plus the actual
byte-swapping with signed integer casts inside was hard to follow.
Switch to a plain uint8_t buffer for integer readout, and use
dedicated system function to convert the big-endian data in the buffer
into unsigned integer in the system endianness, followed by the final
cast to a signed value.
* Add explicit cast to uint32_t in put_objlnk() to prevent warning about
not-fitting integer after byte shift, and update the result type to
uint32_t as well.
* Switch to buffer with sys_put_be16/32/64 when writing integers due to
similar warnings about byte-swapping signed values.
Signed-off-by:
Robert Lubos <robert.lubos@nordicsemi.no>
Loading
Please sign in to comment