Skip to content

Commit 3bf54a9

Browse files
nordic-krchmmahadevan108
authored andcommitted
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 <[email protected]>
1 parent f82ffc9 commit 3bf54a9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/os/cbprintf_packaged.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ int cbprintf_package_convert(void *in_packaged,
11481148
for (unsigned int i = 0; i < scpy_cnt; i++) {
11491149
uint8_t loc = cpy_str_pos[i];
11501150
const char *str = *(const char **)&buf32[loc];
1151-
uint16_t str_len = strl ? strl[i] : 0;
1151+
uint16_t str_len = (strl && (i < strl_len)) ? strl[i] : 0;
11521152

11531153
rv = cb(&loc, 1, ctx);
11541154
if (rv < 0) {

0 commit comments

Comments
 (0)