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>
This commit is contained in:
Krzysztof Chruściński 2024-10-30 12:16:20 +01:00 committed by Mahesh Mahadevan
commit 3bf54a9e85

View file

@ -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) {