diff --git a/lib/mprintf.c b/lib/mprintf.c index 24c1dd555e..8a7c17a7ff 100644 --- a/lib/mprintf.c +++ b/lib/mprintf.c @@ -318,6 +318,11 @@ static int dprintf_Pass1(const char *format, struct va_stack *vto, flags |= FLAGS_PREC; precision = strtol(fmt, &fmt, 10); } + if((flags & (FLAGS_PREC | FLAGS_PRECPARAM)) == + (FLAGS_PREC | FLAGS_PRECPARAM)) + /* it is not permitted to use both kinds of precision for the same + argument */ + return 1; break; case 'h': flags |= FLAGS_SHORT; diff --git a/tests/unit/unit1398.c b/tests/unit/unit1398.c index f68e43ecfa..662e3bdbc2 100644 --- a/tests/unit/unit1398.c +++ b/tests/unit/unit1398.c @@ -89,4 +89,8 @@ rc = curl_msnprintf(output, 16, "%8d%8d", 1234, 5678); fail_unless(rc == 15, "return code should be 15"); fail_unless(!strcmp(output, " 1234 567"), "wrong output"); +/* double precision */ +rc = curl_msnprintf(output, 24, "%.*1$.99d", 3, 5678); +fail_unless(rc == 0, "return code should be 0"); + UNITTEST_STOP