From 0bc01822a27cc4eda42f7d281642c5d663b041fb Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Sat, 12 Dec 2020 13:09:44 -0600 Subject: [PATCH] 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 --- lib/os/cbprintf_complete.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/os/cbprintf_complete.c b/lib/os/cbprintf_complete.c index fb431f57c42..4201080fe03 100644 --- a/lib/os/cbprintf_complete.c +++ b/lib/os/cbprintf_complete.c @@ -360,10 +360,8 @@ static inline const char *extract_width(struct conversion *conv, if (sp != wp) { conv->width_present = true; conv->width_value = width; - if (width != conv->width_value) { - /* Lost width data */ - conv->unsupported = true; - } + conv->unsupported |= ((conv->width_value < 0) + || (width != (size_t)conv->width_value)); } return sp; @@ -396,10 +394,8 @@ static inline const char *extract_prec(struct conversion *conv, size_t prec = extract_decimal(&sp); conv->prec_value = prec; - if (prec != conv->prec_value) { - /* Lost precision data */ - conv->unsupported = true; - } + conv->unsupported |= ((conv->prec_value < 0) + || (prec != (size_t)conv->prec_value)); return sp; }