net: lwm2m: Prevent snprintk warnings on different platforms

Use explicit casting to long long within `snprintk()` and logger
functions to prevent compiler warnings with different
platforms/toolchins (as 64-bit integer can be either represented
as ld or lld depending on platform).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2022-01-13 13:30:58 +01:00 committed by Carles Cufí
parent 486e0a8ff6
commit 9c8d30f099
2 changed files with 5 additions and 3 deletions

View File

@ -4326,7 +4326,7 @@ static int generate_notify_message(struct lwm2m_ctx *ctx,
obs->path.level,
log_strdup(sprint_token(obs->token, obs->tkl)),
log_strdup(lwm2m_sprint_ip_addr(&ctx->remote_addr)),
k_uptime_get());
(long long)k_uptime_get());
obj_inst = get_engine_obj_inst(obs->path.obj_id,
obs->path.obj_inst_id);

View File

@ -8,6 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <inttypes.h>
#include "lwm2m_util.h"
#define SHIFT_LEFT(v, o, m) (((v) << (o)) & (m))
@ -378,7 +379,8 @@ int lwm2m_ftoa(double *input, char *out, size_t outlen, int8_t dec_limit)
int64_t val1 = (int64_t)*input;
int64_t val2 = (*input - (int64_t)*input) * PRECISION64;
len = snprintk(buf, sizeof(buf), "%0*lld", PRECISION64_LEN, llabs(val2));
len = snprintk(buf, sizeof(buf), "%0*lld", PRECISION64_LEN,
(long long)llabs(val2));
if (len != PRECISION64_LEN) {
strcpy(buf, "0");
} else {
@ -418,5 +420,5 @@ int lwm2m_ftoa(double *input, char *out, size_t outlen, int8_t dec_limit)
return snprintk(out, outlen, "%s%lld.%s",
/* handle negative val2 when val1 is 0 */
(val1 == 0 && val2 < 0) ? "-" : "", val1, buf);
(val1 == 0 && val2 < 0) ? "-" : "", (long long)val1, buf);
}