golioth / golioth-zephyr-sdk

Golioth SDK For Zephyr
https://www.golioth.io
Apache License 2.0
67 stars 19 forks source link

coap_req: allow NULL callback #304

Closed ncmiller closed 1 year ago

ncmiller commented 1 year ago

Previously, the cb parameter of golioth_coap_req_cb was required. If it was set to NULL, the system would crash due to NULL dereference.

There have been a couple of instances of crashes which were due to this behavior. In one case, it was inadvertant (user meant to set a callback, but forgot). In the other case, it was intentional (rpc.c and settings.c both set the callback to NULL when sending the response, because they don't care about the response).

It seems like the most reasonable thing to do is to allow for a NULL callback, since there are legitimate requests that don't care to be called back ("fire and forget").

For cases where setting a NULL callback is unintentional, the user will be alerted soon enough when they realize that nothing is happening in response to their request (because they forget to set the callback). But at least there won't be a system crash (which can be hard to track down).

Signed-off-by: Nick Miller nick@golioth.io

github-actions[bot] commented 1 year ago

Visit the preview URL for this PR (updated for commit 7f01a5f):

https://golioth-zephyr-sdk-doxygen-dev--pr304-nick-allow-null-frhuzlrp.web.app

(expires Mon, 24 Oct 2022 19:59:01 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: a389eefadf4b4b68a539327b3459dd66c142cf49