tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Fwd: Re: fmtcheck() query



Rin Okuyama <rokuyama%rk.phys.keio.ac.jp@localhost> wrote:

> On 2017/12/10 2:04, Valery Ushakov wrote:

>> My version currently complains about unused arguments, but there's an
>> XXX comment about that.  For the numbered case the relevant passage
>> is:
>> 
>>    "When numbered argument specifications are used, specifying the Nth
>>    argument requires that all the leading arguments, from the first to
>>    the (N-1)th, are specified in the format string."
>> 
>> i.e. it's ok to consume less, but you have to consume all the ones
>> before.  The latter is obviously not a concern for the usual
>> sequential access.
> 
> Due to this statement of SUS (it is found also in SUSv4
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html),
> it is quite inconvenient to neglect some arguments *intentionally* in
> the framework of printf(3); Missing some arguments in format strings
> should probably be a mistake. I therefore agree with the current
> behavior.

I guess the reason behind that requirement must be the fact that it's
not possible to skip arguments with va_arg().  So e.g. for "%3$s %1$d"
you wouldn't know how to get to the third argument as there's no type
info for the second: is it a 4-byte int, or 8-byte pointer, or 8-byte
double, etc.

Likewise it's obviously ok (technically) to ignore trailing args, you
just never move va_arg() that far into the argument list and there's
no problem with that.

OTOH, we can't tell if the format misses some arguments intentionally.
May be the call site added a new argument and the template message is
now updated to use it, but the translated message was not yet updated
and you'd obviously like to know about that.  This may be a flag
argument, I guess.


>> I don't remember why the code complains if the tempalte refers to the
>> same argument multiple times.  I guess I was too lazy to make sure the
>> two references are compatible.
> 
> It should be allowed, as long as types are consistent, since SUSv4 says:
> 
>     "In format strings containing the "%n$" form of conversion
>     specification, numbered arguments in the argument list can be
>     referenced from the format string as many times as required."

Right, note that the code did not complain about multiple references
in the format, only in the template.  As I said, the original context
this code was written in was checking commands in man.conf, so it's a
bit different from the l10n context, where you have an English message
that is both a format used to actually print something and as a
template used to check translated messages.  In the man.conf case
there's simply no such prototype that is both a format and a template,
so there the template is purely something you supply to fmtcheck() to
tell it what the printf args will be.  In this kind of setup the
template will most likely be a straight sequential format without any
widths or extra formatting, not to mentioned positional arguments.
And, as I said, I was just lazy, so I just stuck that check there
("yeah, i remember about this case"), but made it punt.

> I've changed it to complain only if the same argument is referenced as
> incompatible types.

Rigth, we obviosly need to support it since actual formats can be used
as templates.


> Let us back to the original topic, how fmtcheck(3) be.  I think it
> should be replaced by that based on printf_checkformat().

I'm obviously partial here.  But as long as I don't have to commit and
maintain it ... (did i mention i'm lazy? :)


Thank you.

-uwe



Home | Main Index | Thread Index | Old Index