New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
curl_mfprintf precision parameter isn't working right for floating point #1113
Comments
I'm extending test 557 right now and will add some test strings for this as well and then we can get a patch going. |
(removed a comment I made based on me not reading correctly) |
Remove a single line seems to fix it (I have a larger amount of float tests to add to also make sure we don't regress). diff --git a/lib/mprintf.c b/lib/mprintf.c
index 2c88aa8..2af3d33 100644
--- a/lib/mprintf.c
+++ b/lib/mprintf.c
@@ -301,11 +301,10 @@ static int dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
break;
case '#':
flags |= FLAGS_ALT;
break;
case '.':
- flags |= FLAGS_PREC;
if('*' == *fmt) {
/* The precision is picked from a specified parameter */
flags |= FLAGS_PRECPARAM;
fmt++; |
It would always use precision 1 instead of reading it from the argument list as intended. Reported-by: Ray Satiro Bug: #1113
I decided to push it. I figured you could try it out and if it fixes the issue for you as well, we can close this as fixed. |
While the patch may be correct I still don't get it. Before type specific processing is done the width and the precision are obtained, which makes sense, because that way they can be used for any type. But then why is it overridden for float type? Is it possible that's some artifact that was supposed to be removed? |
I wouldn't call it "overridden". There are two separate code paths, one that output integers and one that deals with floats, so width and precision are handled in two places. The code path for floats checks the flags in the other order so it is sensitive to |
But why. If the bug is the flags are supposed to be mutually exclusive then it's almost the same logic in both places. It looks wrong, the main prec/width logic accounts for negative values and the float prec/width logic does away with that. Try |
You're obviously now talking about other things than this particular issue. I will not deny that the mprintf() function can be improved, but I'm saying that my landed commit fixes the issues you reported. The not handling of negative width seems like a bug for example. But note: A) this function is deprecated and we strongly advice people not to use it in programs and B) we don't use such features in curl or libcurl. I'm not that concerned, but if you feel like it, do add more test cases and fix remaining bugs. |
Well I'm talking about something other than your solution but I think it's related. Fair enough though I will investigate more and start a new issue. |
I did this
I expected the following
2.277000
Instead I got
2.3
Walkthrough
In
dprintf_formatf
after the prescan the precision is set here:p->flags
isFLAGS_PREC | FLAGS_PRECPARAM
,p->precision
is 1,and so the precision is correctly set from the parameter as 6.
Next the specific type processing is done for
FORMAT_DOUBLE
and it resets both width and precision, as seen here:p->flags
andp->precision
are unchanged soprec
is incorrectly set as 1 and that's what causes the output to be rounded to 2.3. I'm baffled by the different processing at this point. It looks like width may have a similar issue.curl/libcurl version
master 2016-11-08 curl-7_51_0-22-g5e6c04f
The text was updated successfully, but these errors were encountered: