1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

nanocoap_sock: fix wrong assertion

The assertion is a bit overeager.
In case of receiving a wrong message ID, we re-try receive without
entering the STATE_REQUEST_SEND state again, so it is expected that
we get a non-NULL ctx/response from sock_udp_recv_buf().

What this assert should actually check is that we don't get a non-NULL
ctx after calling sock_udp_recv_buf() with a non-NULL ctx.

So make this explicit to not falsely fail the assertion.
This commit is contained in:
Benjamin Valentin 2022-06-16 18:48:52 +02:00
parent 809f9ed174
commit 11e40a9d61

View File

@ -175,6 +175,7 @@ ssize_t nanocoap_sock_request_cb(nanocoap_sock_t *sock, coap_pkt_t *pkt,
case STATE_RESPONSE_OK:
DEBUG("nanocoap: waiting for response (timeout: %"PRIu32" µs)\n",
_deadline_left_us(deadline));
const void *old_ctx = ctx;
tmp = sock_udp_recv_buf(sock, &payload, &ctx, _deadline_left_us(deadline), NULL);
/* sock_udp_recv_buf() is supposed to return multiple packet fragments
* when called multiple times with the same context.
@ -183,7 +184,7 @@ ssize_t nanocoap_sock_request_cb(nanocoap_sock_t *sock, coap_pkt_t *pkt,
* releases the packet.
* This assertion will trigger should the behavior change in the future.
*/
if (state != STATE_REQUEST_SEND) {
if (old_ctx) {
assert(tmp == 0 && ctx == NULL);
}
if (tmp == 0) {