lib: cbprintf: ignore l length modifier on float values

%lf is specified to be the same as %f, and should not be marked as
 invalid.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2020-11-17 11:02:05 -06:00 committed by Anas Nashif
commit a9e2b10a86
2 changed files with 21 additions and 3 deletions

View file

@ -538,8 +538,12 @@ int_conv:
break;
}
/* Length modifiers other than L are invalid. */
if ((conv->length_mod != LENGTH_NONE)
/* The l specifier has no effect. Otherwise length
* modifiers other than L are invalid.
*/
if (conv->length_mod == LENGTH_L) {
conv->length_mod = LENGTH_NONE;
} else if ((conv->length_mod != LENGTH_NONE)
&& (conv->length_mod != LENGTH_UPPER_L)) {
conv->invalid = true;
}

View file

@ -731,6 +731,20 @@ static void test_fp_length(void)
double dv = 1.2345;
int rc;
rc = TEST_PRF("/%g/", dv);
if (IS_ENABLED(CONFIG_CBPRINTF_FP_SUPPORT)) {
PRF_CHECK("/1.2345/", rc);
} else {
PRF_CHECK("/%g/", rc);
}
rc = TEST_PRF("/%lg/", dv);
if (IS_ENABLED(CONFIG_CBPRINTF_FP_SUPPORT)) {
PRF_CHECK("/1.2345/", rc);
} else {
PRF_CHECK("/%lg/", rc);
}
rc = TEST_PRF("/%Lg/", (long double)dv);
if (IS_ENABLED(USE_LIBC)) {
PRF_CHECK("/1.2345/", rc);