From d6c25a9a0757af9d13842b7aae9713136e720567 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Fri, 8 Nov 2019 11:17:54 +0100 Subject: [PATCH] coap-server.c: Fix warnings on 32-bit architectures Casting an unsigned long to void * caused a compiler warning on 32-bit architectures. This change uses unsigned int as this has a sufficient range for the respective calculation and introduces a union to avoid the explicit type cast. --- examples/coap-server.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/examples/coap-server.c b/examples/coap-server.c index 5c587e03..030adfbe 100644 --- a/examples/coap-server.c +++ b/examples/coap-server.c @@ -68,6 +68,12 @@ static int support_dynamic = 0; /* This variable is used to mimic long-running tasks that require * asynchronous responses. */ static coap_async_state_t *async = NULL; + +/* A typedef for transfering a value in a void pointer */ +typedef union { + unsigned int val; + void *ptr; +} async_data_t; #endif /* WITHOUT_ASYNC */ #ifdef __GNUC__ @@ -244,11 +250,13 @@ hnd_get_async(coap_context_t *ctx, delay = delay * 10 + (*p - '0'); } + async_data_t data; + data.val = COAP_TICKS_PER_SECOND * delay; async = coap_register_async(ctx, session, request, COAP_ASYNC_SEPARATE | COAP_ASYNC_CONFIRM, - (void *)(COAP_TICKS_PER_SECOND * delay)); + data.ptr); } static void @@ -268,8 +276,9 @@ check_async(coap_context_t *ctx, COAP_RESPONSE_CODE(205), 0, size); if (!response) { coap_log(LOG_DEBUG, "check_async: insufficient memory, we'll try later\n"); - async->appdata = - (void *)((unsigned long)async->appdata + 15 * COAP_TICKS_PER_SECOND); + async_data_t data = { .ptr = async->appdata }; + data.val = data.val + 15 * COAP_TICKS_PER_SECOND; + async->appdata = data.ptr; return; }