treewide: initialize several stack-allocated, but uninitialized timer structs#17855
treewide: initialize several stack-allocated, but uninitialized timer structs#17855miri64 merged 2 commits intoRIOT-OS:masterfrom
Conversation
|
maybe it should be |
I seem to remember there were some problems with |
It all non-mentioned members will be set to zero anyway, but |
| } | ||
| #if IS_USED(MODULE_ZTIMER_USEC) | ||
| ztimer_t timeout_timer; | ||
| ztimer_t timeout_timer = { .base = { .next = NULL } }; |
There was a problem hiding this comment.
If the initialsation is done with = {.callback = _callback_put} the rest of the struct should be initialised (to zero) as well.
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf (p.:142 pdf.:160 l:28 there is an example how to handel partial initialisation)
There was a problem hiding this comment.
If the initialsation is done with
= {.callback = _callback_put}the rest of the struct should be initialised (to zero) as well.http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf (p.:142 pdf.:160 l:28 there is an example how to handel partial initialisation)
That should be the case for the way I picked it as well. That's why I picked a member where I know it should be 0 in any case.
| } | ||
| #if IS_USED(MODULE_ZTIMER_USEC) | ||
| ztimer_t timeout_timer; | ||
| ztimer_t timeout_timer = { .base = { .next = NULL } }; |
There was a problem hiding this comment.
| ztimer_t timeout_timer = { .base = { .next = NULL } }; | |
| ztimer_t timeout_timer = {.callback = _callback_put}; |
There was a problem hiding this comment.
The callback is only needed for when the if is set below. So I would rather not initialize something that is not needed and go for the NULL initializer as picked.
There was a problem hiding this comment.
how about:
| ztimer_t timeout_timer = { .base = { .next = NULL } }; | |
| ztimer_t timeout_timer = { .callback = NULL }; |
or
| ztimer_t timeout_timer = { .base = { .next = NULL } }; | |
| ztimer_t timeout_timer = { 0 }; |
not naming parts of the ztimer_t struct that a user of ztimer should not have to deal with.
There was a problem hiding this comment.
yeah, maybe be a good example.
7b1786b to
a81c5a5
Compare
|
Bump github actions. |
problems? |
i think the problem is generated with c++ where |
IIRC the problem was also related to compiling on OSX using XCode, but tbh I don't know anymore. If there is no problem, I can adjust my style :-) |
|
Just saw this now, and not objecting, but apart from valgrinding RIOT, might these cases be spottable more easily if we (by setting a flag, or merely by stating it needs to be done this way, even if the checks are only in with DEVELHELP) made ztimer complain loudly (as in |
Contribution description
While digging around for my TinyDTLS issue reported in #17849, I did some valgrind probes with
gcoap_dtlsand noticed some missing initializations of timers. This PR fixes those.Testing procedure
Compile
examples/gcoap_dtlswith valgrind support (fornative) and start a shell with valgrind support:open another shell
and send a coap request using the
coapcommand. With this PR, valgrind will remain mostly silent, while in current master it will complain about several "Conditional jump or move depends on uninitialised value(s)"e.g.:
Issues/PRs references
None