* [PATCH] fix printf regression with alt-form octal, default precision
@ 2016-08-04 1:07 Dmitry V. Levin
2016-09-15 16:04 ` Dmitry V. Levin
2016-09-15 16:37 ` Rich Felker
0 siblings, 2 replies; 7+ messages in thread
From: Dmitry V. Levin @ 2016-08-04 1:07 UTC (permalink / raw)
To: musl
commit v1.1.5-10-gb91cdbe2bc8b626aa04dc6e3e84345accf34e4b1 that fixed
behavior of printf with alt-form octal, zero precision, zero value,
at the same time broke alt-form octal with default precision,
e. g. printf("%#09o", 1).
---
src/stdio/vfprintf.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
index 2ecf769..ac2891c 100644
--- a/src/stdio/vfprintf.c
+++ b/src/stdio/vfprintf.c
@@ -570,7 +570,14 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
if (0) {
case 'o':
a = fmt_o(arg.i, z);
- if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1;
+ if (fl&ALT_FORM) {
+ if (p >= 0 && p<z-a+1) {
+ p=z-a+1;
+ } else if (arg.i) {
+ prefix+=5;
+ pl=1;
+ }
+ }
} if (0) {
case 'd': case 'i':
pl=1;
--
ldv
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] fix printf regression with alt-form octal, default precision
2016-08-04 1:07 [PATCH] fix printf regression with alt-form octal, default precision Dmitry V. Levin
@ 2016-09-15 16:04 ` Dmitry V. Levin
2016-09-15 16:22 ` Rich Felker
2016-09-15 16:37 ` Rich Felker
1 sibling, 1 reply; 7+ messages in thread
From: Dmitry V. Levin @ 2016-09-15 16:04 UTC (permalink / raw)
To: musl
Ping?
On Thu, Aug 04, 2016 at 04:07:40AM +0300, Dmitry V. Levin wrote:
> commit v1.1.5-10-gb91cdbe2bc8b626aa04dc6e3e84345accf34e4b1 that fixed
> behavior of printf with alt-form octal, zero precision, zero value,
> at the same time broke alt-form octal with default precision,
> e. g. printf("%#09o", 1).
> ---
> src/stdio/vfprintf.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
> index 2ecf769..ac2891c 100644
> --- a/src/stdio/vfprintf.c
> +++ b/src/stdio/vfprintf.c
> @@ -570,7 +570,14 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
> if (0) {
> case 'o':
> a = fmt_o(arg.i, z);
> - if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1;
> + if (fl&ALT_FORM) {
> + if (p >= 0 && p<z-a+1) {
> + p=z-a+1;
> + } else if (arg.i) {
> + prefix+=5;
> + pl=1;
> + }
> + }
> } if (0) {
> case 'd': case 'i':
> pl=1;
>
> --
> ldv
--
ldv
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] fix printf regression with alt-form octal, default precision
2016-09-15 16:04 ` Dmitry V. Levin
@ 2016-09-15 16:22 ` Rich Felker
2016-09-15 16:25 ` Rich Felker
0 siblings, 1 reply; 7+ messages in thread
From: Rich Felker @ 2016-09-15 16:22 UTC (permalink / raw)
To: musl
On Thu, Sep 15, 2016 at 07:04:34PM +0300, Dmitry V. Levin wrote:
> Ping?
>
> On Thu, Aug 04, 2016 at 04:07:40AM +0300, Dmitry V. Levin wrote:
> > commit v1.1.5-10-gb91cdbe2bc8b626aa04dc6e3e84345accf34e4b1 that fixed
> > behavior of printf with alt-form octal, zero precision, zero value,
> > at the same time broke alt-form octal with default precision,
> > e. g. printf("%#09o", 1).
> > ---
> > src/stdio/vfprintf.c | 9 ++++++++-
> > 1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
> > index 2ecf769..ac2891c 100644
> > --- a/src/stdio/vfprintf.c
> > +++ b/src/stdio/vfprintf.c
> > @@ -570,7 +570,14 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
> > if (0) {
> > case 'o':
> > a = fmt_o(arg.i, z);
> > - if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1;
> > + if (fl&ALT_FORM) {
> > + if (p >= 0 && p<z-a+1) {
> > + p=z-a+1;
> > + } else if (arg.i) {
> > + prefix+=5;
> > + pl=1;
> > + }
> > + }
This still does not fix all cases, e.g. printf("%#09.0o\n", 0);
I'm going to try to understand what's going on and make a complete
fix.
Rich
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] fix printf regression with alt-form octal, default precision
2016-09-15 16:22 ` Rich Felker
@ 2016-09-15 16:25 ` Rich Felker
0 siblings, 0 replies; 7+ messages in thread
From: Rich Felker @ 2016-09-15 16:25 UTC (permalink / raw)
To: musl
On Thu, Sep 15, 2016 at 12:22:57PM -0400, Rich Felker wrote:
> On Thu, Sep 15, 2016 at 07:04:34PM +0300, Dmitry V. Levin wrote:
> > Ping?
> >
> > On Thu, Aug 04, 2016 at 04:07:40AM +0300, Dmitry V. Levin wrote:
> > > commit v1.1.5-10-gb91cdbe2bc8b626aa04dc6e3e84345accf34e4b1 that fixed
> > > behavior of printf with alt-form octal, zero precision, zero value,
> > > at the same time broke alt-form octal with default precision,
> > > e. g. printf("%#09o", 1).
> > > ---
> > > src/stdio/vfprintf.c | 9 ++++++++-
> > > 1 file changed, 8 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
> > > index 2ecf769..ac2891c 100644
> > > --- a/src/stdio/vfprintf.c
> > > +++ b/src/stdio/vfprintf.c
> > > @@ -570,7 +570,14 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
> > > if (0) {
> > > case 'o':
> > > a = fmt_o(arg.i, z);
> > > - if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1;
> > > + if (fl&ALT_FORM) {
> > > + if (p >= 0 && p<z-a+1) {
> > > + p=z-a+1;
> > > + } else if (arg.i) {
> > > + prefix+=5;
> > > + pl=1;
> > > + }
> > > + }
>
> This still does not fix all cases, e.g. printf("%#09.0o\n", 0);
Oh, never mind, '0' flag is specified to be ignored if a precision is
specified; this isn't a bug. I'll check and see if anything else is
wrong.
Rich
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] fix printf regression with alt-form octal, default precision
2016-08-04 1:07 [PATCH] fix printf regression with alt-form octal, default precision Dmitry V. Levin
2016-09-15 16:04 ` Dmitry V. Levin
@ 2016-09-15 16:37 ` Rich Felker
2016-09-15 18:14 ` Dmitry V. Levin
1 sibling, 1 reply; 7+ messages in thread
From: Rich Felker @ 2016-09-15 16:37 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 1315 bytes --]
On Thu, Aug 04, 2016 at 04:07:40AM +0300, Dmitry V. Levin wrote:
> commit v1.1.5-10-gb91cdbe2bc8b626aa04dc6e3e84345accf34e4b1 that fixed
> behavior of printf with alt-form octal, zero precision, zero value,
> at the same time broke alt-form octal with default precision,
> e. g. printf("%#09o", 1).
> ---
> src/stdio/vfprintf.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
> index 2ecf769..ac2891c 100644
> --- a/src/stdio/vfprintf.c
> +++ b/src/stdio/vfprintf.c
> @@ -570,7 +570,14 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
> if (0) {
> case 'o':
> a = fmt_o(arg.i, z);
> - if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1;
> + if (fl&ALT_FORM) {
> + if (p >= 0 && p<z-a+1) {
> + p=z-a+1;
> + } else if (arg.i) {
> + prefix+=5;
> + pl=1;
> + }
> + }
> } if (0) {
> case 'd': case 'i':
> pl=1;
I think the attached simpler patch should work just as well. Adjusting
'p' to implement '#' was probably a bad idea since it makes the later
code paths think an explicit precision was specified when it was not.
"Add a prefix of '0' when p is too short to have a leading '0'
already" seems like safer logic.
I'm also attaching some test cases I ran.
Rich
[-- Attachment #2: octal_alt_form.diff --]
[-- Type: text/plain, Size: 435 bytes --]
diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
index 2ecf769..e439a07 100644
--- a/src/stdio/vfprintf.c
+++ b/src/stdio/vfprintf.c
@@ -570,7 +570,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
if (0) {
case 'o':
a = fmt_o(arg.i, z);
- if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1;
+ if ((fl&ALT_FORM) && p<z-a+1) prefix+=5, pl=1;
} if (0) {
case 'd': case 'i':
pl=1;
[-- Attachment #3: alt_form_octal.c --]
[-- Type: text/plain, Size: 403 bytes --]
#include <stdio.h>
int main()
{
printf("%#.0o\n", 0);
printf("%#.0o\n", 1);
printf("%#o\n", 0);
printf("%#o\n", 1);
printf("%#09o\n", 0);
printf("%#09o\n", 1);
printf("%#09.0o\n", 0);
printf("%#09.0o\n", 1);
printf("%#9o\n", 0);
printf("%#9o\n", 1);
printf("%#9.0o\n", 0);
printf("%#9.0o\n", 1);
printf("%#.1o\n", 0);
printf("%#.1o\n", 1);
printf("%#.2o\n", 0);
printf("%#.2o\n", 1);
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] fix printf regression with alt-form octal, default precision
2016-09-15 16:37 ` Rich Felker
@ 2016-09-15 18:14 ` Dmitry V. Levin
2016-09-16 21:58 ` Rich Felker
0 siblings, 1 reply; 7+ messages in thread
From: Dmitry V. Levin @ 2016-09-15 18:14 UTC (permalink / raw)
To: musl
On Thu, Sep 15, 2016 at 12:37:57PM -0400, Rich Felker wrote:
> On Thu, Aug 04, 2016 at 04:07:40AM +0300, Dmitry V. Levin wrote:
> > commit v1.1.5-10-gb91cdbe2bc8b626aa04dc6e3e84345accf34e4b1 that fixed
> > behavior of printf with alt-form octal, zero precision, zero value,
> > at the same time broke alt-form octal with default precision,
> > e. g. printf("%#09o", 1).
> > ---
> > src/stdio/vfprintf.c | 9 ++++++++-
> > 1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
> > index 2ecf769..ac2891c 100644
> > --- a/src/stdio/vfprintf.c
> > +++ b/src/stdio/vfprintf.c
> > @@ -570,7 +570,14 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
> > if (0) {
> > case 'o':
> > a = fmt_o(arg.i, z);
> > - if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1;
> > + if (fl&ALT_FORM) {
> > + if (p >= 0 && p<z-a+1) {
> > + p=z-a+1;
> > + } else if (arg.i) {
> > + prefix+=5;
> > + pl=1;
> > + }
> > + }
> > } if (0) {
> > case 'd': case 'i':
> > pl=1;
>
> I think the attached simpler patch should work just as well. Adjusting
> 'p' to implement '#' was probably a bad idea since it makes the later
> code paths think an explicit precision was specified when it was not.
> "Add a prefix of '0' when p is too short to have a leading '0'
> already" seems like safer logic.
>
> I'm also attaching some test cases I ran.
>
> Rich
>
> diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
> index 2ecf769..e439a07 100644
> --- a/src/stdio/vfprintf.c
> +++ b/src/stdio/vfprintf.c
> @@ -570,7 +570,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
> if (0) {
> case 'o':
> a = fmt_o(arg.i, z);
> - if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1;
> + if ((fl&ALT_FORM) && p<z-a+1) prefix+=5, pl=1;
> } if (0) {
> case 'd': case 'i':
> pl=1;
Yes, this also works, thanks.
--
ldv
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] fix printf regression with alt-form octal, default precision
2016-09-15 18:14 ` Dmitry V. Levin
@ 2016-09-16 21:58 ` Rich Felker
0 siblings, 0 replies; 7+ messages in thread
From: Rich Felker @ 2016-09-16 21:58 UTC (permalink / raw)
To: musl
On Thu, Sep 15, 2016 at 09:14:56PM +0300, Dmitry V. Levin wrote:
> On Thu, Sep 15, 2016 at 12:37:57PM -0400, Rich Felker wrote:
> > On Thu, Aug 04, 2016 at 04:07:40AM +0300, Dmitry V. Levin wrote:
> > > commit v1.1.5-10-gb91cdbe2bc8b626aa04dc6e3e84345accf34e4b1 that fixed
> > > behavior of printf with alt-form octal, zero precision, zero value,
> > > at the same time broke alt-form octal with default precision,
> > > e. g. printf("%#09o", 1).
> > > ---
> > > src/stdio/vfprintf.c | 9 ++++++++-
> > > 1 file changed, 8 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
> > > index 2ecf769..ac2891c 100644
> > > --- a/src/stdio/vfprintf.c
> > > +++ b/src/stdio/vfprintf.c
> > > @@ -570,7 +570,14 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
> > > if (0) {
> > > case 'o':
> > > a = fmt_o(arg.i, z);
> > > - if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1;
> > > + if (fl&ALT_FORM) {
> > > + if (p >= 0 && p<z-a+1) {
> > > + p=z-a+1;
> > > + } else if (arg.i) {
> > > + prefix+=5;
> > > + pl=1;
> > > + }
> > > + }
> > > } if (0) {
> > > case 'd': case 'i':
> > > pl=1;
> >
> > I think the attached simpler patch should work just as well. Adjusting
> > 'p' to implement '#' was probably a bad idea since it makes the later
> > code paths think an explicit precision was specified when it was not.
> > "Add a prefix of '0' when p is too short to have a leading '0'
> > already" seems like safer logic.
> >
> > I'm also attaching some test cases I ran.
> >
> > Rich
> >
> > diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
> > index 2ecf769..e439a07 100644
> > --- a/src/stdio/vfprintf.c
> > +++ b/src/stdio/vfprintf.c
> > @@ -570,7 +570,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
> > if (0) {
> > case 'o':
> > a = fmt_o(arg.i, z);
> > - if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1;
> > + if ((fl&ALT_FORM) && p<z-a+1) prefix+=5, pl=1;
> > } if (0) {
> > case 'd': case 'i':
> > pl=1;
>
> Yes, this also works, thanks.
OK, I'm committing this version. Thanks!
Rich
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-09-16 21:58 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-04 1:07 [PATCH] fix printf regression with alt-form octal, default precision Dmitry V. Levin
2016-09-15 16:04 ` Dmitry V. Levin
2016-09-15 16:22 ` Rich Felker
2016-09-15 16:25 ` Rich Felker
2016-09-15 16:37 ` Rich Felker
2016-09-15 18:14 ` Dmitry V. Levin
2016-09-16 21:58 ` Rich Felker
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).