Browse Source

lib: os: cbprintf_packaged: Fix cbprintf_package_convert

When conversion is done in two steps (output length calculation
followed by the actual conversion), it was failing when helper
array for holding calculated string length from the first
conversion run was shorter than number of strings that were
supposed to be appended to the package. Fix by taking into
account strl_len to determine if length can be taken from the
array or need to be calculated again.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
pull/80751/head
Krzysztof Chruściński 8 months ago committed by Mahesh Mahadevan
parent
commit
3bf54a9e85
  1. 2
      lib/os/cbprintf_packaged.c

2
lib/os/cbprintf_packaged.c

@ -1148,7 +1148,7 @@ calculate_string_length: @@ -1148,7 +1148,7 @@ calculate_string_length:
for (unsigned int i = 0; i < scpy_cnt; i++) {
uint8_t loc = cpy_str_pos[i];
const char *str = *(const char **)&buf32[loc];
uint16_t str_len = strl ? strl[i] : 0;
uint16_t str_len = (strl && (i < strl_len)) ? strl[i] : 0;
rv = cb(&loc, 1, ctx);
if (rv < 0) {

Loading…
Cancel
Save