zephyr/lib/utils
Christoph Winklhofer 061e345972 json: Fix calculation of object size
The calculation of the object size may be incorrect when the size of
a field is smaller than the struct alignment. When such a struct is
used in an array field, the decoded object contains wrong values.

The alignment influences the object size. For example the following
struct has a calculated object size of 8 bytes, however due to
alignment the real size of the struct is 12 bytes:

struct test_bool {
  bool b1; /* offset 0, size 1 */
           /* 3-byte padding */
  int i1;  /* offset 4, size 4 */
  bool b2; /* offset 8, size 1 */
           /* 3-byte padding */
};

This commit changes the object size calculation and computes the size
with the offset and size of the last field in the struct (rounded up
by the struct alignment).

Fixes: #85121
Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
2025-04-08 11:44:51 +02:00
..
base64.c
bitarray.c lib: check null pointer before taking lock for bitarray 2024-06-14 19:18:28 +02:00
CMakeLists.txt lib: utils: add consistent overhead byte stuffing 2025-03-11 05:36:49 +01:00
cobs.c lib: utils: add consistent overhead byte stuffing 2025-03-11 05:36:49 +01:00
dec.c
hex.c coding guidelines: comply with MISRA Rule 12.1. 2024-06-13 20:28:23 -04:00
json.c json: Fix calculation of object size 2025-04-08 11:44:51 +02:00
Kconfig ring_buffer: shrink size of struct ring_buf 2025-03-11 08:59:05 +01:00
notify.c
onoff.c lib: change controlling expressions in if/while to Boolean 2024-06-11 20:03:34 +03:00
rb.c lib: avoided increments/decrements with side effects 2024-06-21 08:48:15 -04:00
ring_buffer.c ring_buffer: shrink size of struct ring_buf 2025-03-11 08:59:05 +01:00
timeutil.c sys: timeutil: expose and use macro for base year 2024-08-29 11:38:28 +02:00
utf8.c zephyr: Add zero-len check for utf8_trunc 2024-06-27 08:48:31 -04:00
winstream.c