Re: proposal: a width specification for s specifier (format function), fix behave when positional and ordered placeholders are used - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: proposal: a width specification for s specifier (format function), fix behave when positional and ordered placeholders are used
Date
Msg-id CAFj8pRDB+r-h=5K12R8XXFe+sWzeEDGvm3F-t3z2d7x0SX-B6g@mail.gmail.com
Whole thread Raw
In response to Re: proposal: a width specification for s specifier (format function), fix behave when positional and ordered placeholders are used  (Stephen Frost <sfrost@snowman.net>)
Responses Re: proposal: a width specification for s specifier (format function), fix behave when positional and ordered placeholders are used  (Stephen Frost <sfrost@snowman.net>)
List pgsql-hackers
2012/12/29 Stephen Frost <sfrost@snowman.net>:
> Pavel,
>
> * Pavel Stehule (pavel.stehule@gmail.com) wrote:
>> 2012/12/29 Stephen Frost <sfrost@snowman.net>:
>> > This is correct, if we're matching glibc (and SUS, I believe), isn't it?
>> > You're not allowed to mix '%2$s' type parameters and '%s' in a single
>> > format.
>>
>> I am not sure, please recheck
>
> According to the man pages on my Ubuntu system, under 'Format of the
> format string':
>
> -------------------
> If the style using '$' is used, it must be  used  throughout  for
> all  conversions  taking an argument and all width and precision
> arguments, but it may be mixed with "%%" formats which do not consume
> an argument.
> -------------------
>
>> pavel ~ $ cat test.c
>> #include <stdio.h>
>>
>> void main()
>> {
>>
>>   printf("%s %2$s %s\n", "AHOJ", "Svete");
>> }
>>
>> pavel ~ $ gcc test.c # no warning here
>
> You didn't turn any on...
>
> sfrost@tamriel:/home/sfrost> gcc -o qq -Wall test.c
> test.c: In function ‘main’:
> test.c:5:3: warning: $ operand number used after format without operand number [-Wformat]

ok, so what is proposed solution?

I see two possibilities - a) applying my current patch - although it
is not fully correct, b) new patch, that do necessary check and raise
more descriptive error message.

I have not strong preferences in this topic - both variants are
acceptable for me and I invite any community opinion. But current
state is not intuitive and should be fixed.

Regards

Pavel

>
>         Thanks,
>
>                 Stephen



pgsql-hackers by date:

Previous
From: Stephen Frost
Date:
Subject: Re: pg_dump transaction's read-only mode
Next
From: Stephen Frost
Date:
Subject: Re: Hot Standby conflict resolution handling