-
Notifications
You must be signed in to change notification settings - Fork 2.1k
treewide: initialize several stack-allocated, but uninitialized timer structs #17855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -120,14 +120,14 @@ ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt_out, | |||||||||||||
| return -EINVAL; | ||||||||||||||
| } | ||||||||||||||
| #if IS_USED(MODULE_ZTIMER_USEC) | ||||||||||||||
| ztimer_t timeout_timer; | ||||||||||||||
| ztimer_t timeout_timer = { .base = { .next = NULL } }; | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about:
Suggested change
or
Suggested change
not naming parts of the ztimer_t struct that a user of ztimer should not have to deal with.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, maybe be a good example. |
||||||||||||||
| if ((timeout != SOCK_NO_TIMEOUT) && (timeout != 0)) { | ||||||||||||||
| timeout_timer.callback = _callback_put; | ||||||||||||||
| timeout_timer.arg = reg; | ||||||||||||||
| ztimer_set(ZTIMER_USEC, &timeout_timer, timeout); | ||||||||||||||
| } | ||||||||||||||
| #elif IS_USED(MODULE_XTIMER) | ||||||||||||||
| xtimer_t timeout_timer; | ||||||||||||||
| xtimer_t timeout_timer = { .callback = NULL }; | ||||||||||||||
|
|
||||||||||||||
| /* xtimer_spin would make this never receive anything. | ||||||||||||||
| * Avoid that by setting the minimal not spinning timeout. */ | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.