From 7a94b364300eb98e0bf5c3b47aad6310d64acd9f Mon Sep 17 00:00:00 2001 From: Lars Pfau Date: Wed, 18 May 2022 17:36:54 +0200 Subject: [PATCH] sys/phydat: fix phydat_to_json dim precondition --- sys/include/phydat.h | 4 ++-- sys/phydat/phydat_json.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/include/phydat.h b/sys/include/phydat.h index b83f11c2cc..db8036a06c 100644 --- a/sys/include/phydat.h +++ b/sys/include/phydat.h @@ -277,11 +277,11 @@ void phydat_fit(phydat_t *dat, const int32_t *values, unsigned int dim); * for @ref UNIT_NONE. * * @param[in] data data to encode - * @param[in] dim dimensions used in @p data, MUST be > 0 and < PHYDAT_DIM + * @param[in] dim dimensions used in @p data, MUST be > 0 and <= PHYDAT_DIM * @param[out] buf target buffer for the JSON string, or NULL * * @pre @p dim > 0 - * @pre @p dim < PHYDAT_DIM + * @pre @p dim <= PHYDAT_DIM * * @return number of bytes (potentially) written to @p buf, including `\0` * terminator diff --git a/sys/phydat/phydat_json.c b/sys/phydat/phydat_json.c index d2c3675772..176016f8c0 100644 --- a/sys/phydat/phydat_json.c +++ b/sys/phydat/phydat_json.c @@ -43,7 +43,7 @@ static size_t _bool_to_str(int16_t val, char *buf) size_t phydat_to_json(const phydat_t *data, size_t dim, char *buf) { - assert((dim > 0) && (dim < PHYDAT_DIM)); + assert((dim > 0) && (dim <= PHYDAT_DIM)); size_t pos = 0;