posix_sockets.c: Fix 2 byte int compilation errors#19946
posix_sockets.c: Fix 2 byte int compilation errors#19946bors[bot] merged 1 commit intoRIOT-OS:masterfrom
Conversation
sys/posix/sockets/posix_sockets.c
Outdated
| socket_t *s; | ||
| struct timeval *tv; | ||
| const uint32_t max_timeout_secs = UINT32_MAX / (1000 * 1000); | ||
| const uint32_t max_timeout_secs = UINT32_MAX / (1000UL * 1000); |
There was a problem hiding this comment.
| const uint32_t max_timeout_secs = UINT32_MAX / (1000UL * 1000); | |
| const uint32_t max_timeout_secs = UINT32_MAX / US_PER_SEC; |
should make it clearer what's going on (from time_units.h)
There was a problem hiding this comment.
Updated as suggested.
There was a problem hiding this comment.
Did you push your changes?
There was a problem hiding this comment.
Not yet - thinking about the time_t definition issue for avr cpus.
sys/posix/sockets/posix_sockets.c
Outdated
| tv = (struct timeval *) option_value; | ||
|
|
||
| if (tv->tv_sec < 0 || tv->tv_usec < 0) { | ||
| /* tv_sec is unit32_t, so never negative */ |
There was a problem hiding this comment.
Are you sure? According to the standard, it's time_t, which is usually int64_t these days.
There was a problem hiding this comment.
I agree that the standard refers to time_t, and the 3 definitions of tv_sec all refer to time_t in RIOT as per
# pri kind tag file
1 F C m tv_sec ./cpu/esp8266/include/sys/types.h
struct:timespec
time_t tv_sec; /* Seconds */
2 F m tv_sec ./cpu/avr8_common/avr_libc_extra/include/sys/time.h
struct:timeval
time_t tv_sec; /**< seconds */
3 F m tv_sec ./cpu/avr8_common/avr_libc_extra/include/vendor/time.h
struct:timespec
time_t tv_sec;
However, in RIOT, in the 3 places where time_t is defined we have
# pri kind tag file
1 F C t time_t ./cpu/esp8266/include/sys/types.h
typedef _TIME_T_ time_t;
2 F t time_t ./cpu/avr8_common/avr_libc_extra/include/sys/types.h
typedef uint32_t time_t; /**< Used for time in seconds */
3 F t time_t ./cpu/avr8_common/avr_libc_extra/include/vendor/time.h
typedef uint32_t time_t;
but _TIME_T_ is not defined anywhere.
So it looks like this change will have to be some sort of conditional based on an AVR build, but haven't worked out which conditional to use yet.
There was a problem hiding this comment.
Ah so you are getting a build warning (that gets promited to error) on AVR with this check in place?
There was a problem hiding this comment.
I'd be fine with dropping that check if it makes things easier, it might as well have been an assert().
There was a problem hiding this comment.
Without this PR, the following is reported (assuming POSIX_SETSOCKOPT is defined and building for AVR)
/home/jon/RIOT/sys/posix/sockets/posix_sockets.c:1147:20: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
if (tv->tv_sec < 0 || tv->tv_usec < 0) {
^
cc1: all warnings being treated as errors
|
Changes pushed as a separate commit. Before and after this PR change can be tested with this additional change and |
|
feel free to squash |
619f3cb to
ed64f06
Compare
|
squashed and pushed. |
|
bors merge |
19946: posix_sockets.c: Fix 2 byte int compilation errors r=benpicco a=mrdeep1 19953: boards/esp32s3-wt32-sc01-plus: fix Kconfig r=aabadie a=gschorcht ### Contribution description This PR fixes a remaining Kconfig mismatch. It should fix the last compilation problem of the nightly. ### Testing procedure ``` python3 dist/tools/compile_test/compile_like_murdock.py -a tests/drivers/ili9341/ -b esp32s3-wt32-sc01-plus ``` should fail w/o this PR but should succeed with this PR. ### Issues/PRs references Co-authored-by: Jon Shallow <[email protected]> Co-authored-by: Gunar Schorcht <[email protected]>
|
Build failed (retrying...): |
19946: posix_sockets.c: Fix 2 byte int compilation errors r=benpicco a=mrdeep1 Co-authored-by: Jon Shallow <[email protected]>
|
Build failed: |
|
bors merge |
|
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
Contribution description
When building with
POSIX_SETSOCKOPTdefined (to be able to use the posixsetsockopt()function to setSO_RCVTIMEO), this code fails to build with 16 bit integer compilers for some of the boards as there is an integer overflow for1000*1000.There is also an invalid test that the provided
tv->tv_secis less than 0 as it is auint32_t.Testing procedure
Murdock should fail if the following change is made to tests/sys/posix_sleep/Makefile without this PR.
Issues/PRs references
None.