Skip to content

Commit 0bc0182

Browse files
pabigotcarlescufi
authored andcommitted
lib: cbprintf: improve coverage
Providing a literal width or precision that exceeds the non-negative range of int does not appear to be rejected by the standard, but it does produce a build diagnostic so we can't test it. Switch to an equivalent form that doesn't affect line coverage. Signed-off-by: Peter Bigot <[email protected]>
1 parent 9e5b50a commit 0bc0182

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

lib/os/cbprintf_complete.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,8 @@ static inline const char *extract_width(struct conversion *conv,
360360
if (sp != wp) {
361361
conv->width_present = true;
362362
conv->width_value = width;
363-
if (width != conv->width_value) {
364-
/* Lost width data */
365-
conv->unsupported = true;
366-
}
363+
conv->unsupported |= ((conv->width_value < 0)
364+
|| (width != (size_t)conv->width_value));
367365
}
368366

369367
return sp;
@@ -396,10 +394,8 @@ static inline const char *extract_prec(struct conversion *conv,
396394
size_t prec = extract_decimal(&sp);
397395

398396
conv->prec_value = prec;
399-
if (prec != conv->prec_value) {
400-
/* Lost precision data */
401-
conv->unsupported = true;
402-
}
397+
conv->unsupported |= ((conv->prec_value < 0)
398+
|| (prec != (size_t)conv->prec_value));
403399

404400
return sp;
405401
}

0 commit comments

Comments
 (0)