Skip to content

Conversation

tpambor
Copy link
Contributor

@tpambor tpambor commented May 30, 2025

htonl() and htons() take uint32_t/uint16_t as argument. Add the 'u' suffix to constants in net_6lo_addr_16_bit_compressible to ensure the correct unsigned type is used and to avoid undefined behavior if these functions are implemented as macros using bit shifts.

This fixes the following errors reported by UBSAN

zephyr/subsys/net/ip/6lo.c:131:49: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
zephyr/subsys/net/ip/6lo.c:131:49: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
zephyr/subsys/net/ip/6lo.c:131:49: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
zephyr/subsys/net/ip/6lo.c:131:49: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'

This is a step towards fixing #90882.

htonl() and htons() take uint32_t/uint16_t as argument. Add the 'u' suffix
to constants to ensure the correct unsigned type is used and to avoid
undefined behavior if these functions are implemented as macros using
bit shifts.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
@sonarqubecloud
Copy link

@dkalowsk dkalowsk merged commit a760ba7 into zephyrproject-rtos:main Jun 4, 2025
28 checks passed
@ghost ghost mentioned this pull request Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants