Skip to content

Commit

Permalink
lib: os: cbprintf_packaged: Fix cbprintf_package_convert
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nordic-krch authored and mmahadevan108 committed Nov 1, 2024
1 parent f82ffc9 commit 3bf54a9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/os/cbprintf_packaged.c
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ int cbprintf_package_convert(void *in_packaged,
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) {
Expand Down

0 comments on commit 3bf54a9

Please sign in to comment.