{"action":"created","issue":{"url":"https://api.github.com/repos/curl/curl/issues/1113","repository_url":"https://api.github.com/repos/curl/curl","labels_url":"https://api.github.com/repos/curl/curl/issues/1113/labels{/name}","comments_url":"https://api.github.com/repos/curl/curl/issues/1113/comments","events_url":"https://api.github.com/repos/curl/curl/issues/1113/events","html_url":"https://github.com/curl/curl/issues/1113","id":187918421,"number":1113,"title":"curl_mfprintf precision parameter isn't working right for floating point","user":{"login":"jay","id":965580,"avatar_url":"https://avatars.githubusercontent.com/u/965580?v=3","gravatar_id":"","url":"https://api.github.com/users/jay","html_url":"https://github.com/jay","followers_url":"https://api.github.com/users/jay/followers","following_url":"https://api.github.com/users/jay/following{/other_user}","gists_url":"https://api.github.com/users/jay/gists{/gist_id}","starred_url":"https://api.github.com/users/jay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jay/subscriptions","organizations_url":"https://api.github.com/users/jay/orgs","repos_url":"https://api.github.com/users/jay/repos","events_url":"https://api.github.com/users/jay/events{/privacy}","received_events_url":"https://api.github.com/users/jay/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-08T07:14:14Z","updated_at":"2016-11-08T09:30:23Z","closed_at":null,"body":"### I did this\r\n~~~c\r\ncurl_mfprintf(stdout, \"%.*f\", 6, 2.277000);\r\n~~~\r\n### I expected the following\r\n2.277000\r\n### Instead I got\r\n2.3\r\n### Walkthrough\r\nIn [`dprintf_formatf`](https://github.com/curl/curl/blob/curl-7_51_0/lib/mprintf.c#L562) after the prescan the precision is set [here](https://github.com/curl/curl/blob/curl-7_51_0/lib/mprintf.c#L678-L691):\r\n~~~c\r\n    /* pick up the specified precision */\r\n    if(p->flags & FLAGS_PRECPARAM) {\r\n      prec = (long)vto[p->precision].data.num.as_signed;\r\n      param_num++; /* since the precision is extracted from a parameter, we\r\n                      must skip that to get to the next one properly */\r\n      if(prec < 0)\r\n        /* \"A negative precision is taken as if the precision were\r\n           omitted.\" */\r\n        prec = -1;\r\n    }\r\n    else if(p->flags & FLAGS_PREC)\r\n      prec = p->precision;\r\n    else\r\n      prec = -1;\r\n~~~\r\n`p->flags` is  `FLAGS_PREC | FLAGS_PRECPARAM`,\r\n`p->precision` is 1,\r\nand so the precision is correctly set from the parameter as 6.\r\n\r\nNext the specific type processing is done for `FORMAT_DOUBLE` and it resets both width and precision, as seen [here](https://github.com/curl/curl/blob/curl-7_51_0/lib/mprintf.c#L902-L906):\r\n~~~c\r\n        prec = -1;\r\n        if(p->flags & FLAGS_PREC)\r\n          prec = p->precision;\r\n        else if(p->flags & FLAGS_PRECPARAM)\r\n          prec = (long)vto[p->precision].data.num.as_signed;\r\n~~~\r\n`p->flags` and `p->precision` are unchanged so `prec` 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. \r\n\r\n### curl/libcurl version\r\nmaster 2016-11-08 curl-7_51_0-22-g[5e6c04f](https://github.com/curl/curl/commit/5e6c04f)\r\n"},"comment":{"url":"https://api.github.com/repos/curl/curl/issues/comments/259087868","html_url":"https://github.com/curl/curl/issues/1113#issuecomment-259087868","issue_url":"https://api.github.com/repos/curl/curl/issues/1113","id":259087868,"user":{"login":"bagder","id":177011,"avatar_url":"https://avatars.githubusercontent.com/u/177011?v=3","gravatar_id":"","url":"https://api.github.com/users/bagder","html_url":"https://github.com/bagder","followers_url":"https://api.github.com/users/bagder/followers","following_url":"https://api.github.com/users/bagder/following{/other_user}","gists_url":"https://api.github.com/users/bagder/gists{/gist_id}","starred_url":"https://api.github.com/users/bagder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bagder/subscriptions","organizations_url":"https://api.github.com/users/bagder/orgs","repos_url":"https://api.github.com/users/bagder/repos","events_url":"https://api.github.com/users/bagder/events{/privacy}","received_events_url":"https://api.github.com/users/bagder/received_events","type":"User","site_admin":false},"created_at":"2016-11-08T09:30:23Z","updated_at":"2016-11-08T09:30:23Z","body":"(removed a comment I made based on me not reading correctly)"}}
{"actor":{"display_login":"bagder"}}