-
Notifications
You must be signed in to change notification settings - Fork 557
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
printf warns about too few arguments, but not too many #13534
Comments
From @avarCreated by @avarFor a long time perl has warned about too few arguments in printf: $ perl -wle 'print $]; printf "%s%s", qw(a)' I've now just fixed a long-standing 6 year old bug in a codebase I $ perl -wle 'print $]; printf "%s%s", qw(a b c)' It would be very nice if perl were to have a warning for Perl Info
|
From @jkeenanOn Fri Jan 17 13:18:02 2014, avar wrote:
I am opposed to this proposal. This would impose more complex behavior on Perl 5's printf than on bash's printf or C's printf. I don't see anything in 'man printf' or 'man 3 printf' on either Linux or Darwin that suggests that such a warning would be desirable. Nor do I see why we should go beyond the behavior documented in, say, http://pubs.opengroup.org/onlinepubs/009695399/functions/printf.html. I believe this would fall into the category of excessive hand-holding. YAGNI. Thank you very much. |
The RT System itself - Status changed from 'new' to 'open' |
From @avarOn Sat, Jan 18, 2014 at 1:26 AM, James E Keenan via RT
Warnings like these are usually (always?) not documented in the C It's interesting to see what GCC and Clang have done in this case, $ gcc -Wall -o toomany toomany.c ; ./toomany Of course unlike perl they can do so with static analysis so it might So it seems trivial to emit a warning at the end of it when you find I have a WIP patch that does just that. It's not ready yet because I Too many arguments. You passed 7 on the stack but your format only From code code in MM_Any.pm that indeed passes in 7 printf arguments So no, I think I might just need this, and it does look quite useful |
From @jkeenanOn Fri Jan 17 17:41:38 2014, avarab@gmail.com wrote:
[snip] Thank you for providing that additional information. I look forward to seeing your patch (though others will probably be better judges of it than I). jimk |
From zefram@fysh.orgAEvar Arnfjorth Bjarmason wrote:
If it were not so, it would be at risk of using more arguments than were
Nice. I like this warning. Wording suggestion: "on the stack" is It would be even niftier if we could statically analyse printf expressions -zefram |
From @iabynOn Sat, Jan 18, 2014 at 07:01:21PM +0000, Zefram wrote:
Me too. Although I think it should go into blead just after 5.20 is -- |
From @wolfsageOn Fri, Jan 17, 2014 at 8:40 PM, Ævar Arnfjörð Bjarmason
Awesome! I would love to see this included as well. Thank you very much. -- Matthew Horsfall (alh) |
From @druud62On 2014-01-18 21:16, Dave Mitchell wrote:
I would not warn like this if the format string contains parameter -- |
From @khwilliamsonOn 01/18/2014 01:16 PM, Dave Mitchell wrote:
+1 |
From @AbigailOn Sat, Jan 18, 2014 at 07:01:21PM +0000, Zefram wrote:
If the constant format followed by all-scalar parameter expressions is Abigail |
From @druud62On 2014-01-18 22:23, Dr.Ruud wrote:
perl -wE' -- |
From @ap* Ævar Arnfjörð Bjarmason <avarab@gmail.com> [2014-01-18 02:45]:
Please make sure it has its own category so that it can be silenced
I cannot find any other two-sentences warning, except this one: Non-octal character '%c'. Resolved as "%s" (Aside: why is that one two sentences? I think it should use parens to The existing warning for missing printf arguments looks like this: $ perl -we 'printf "%s %s %s %s", 1' That’s annoying. Plus I was hoping for precedent for how to include the There is no such established style elsewhere either: $ perl -e 'sub x($) {} x(1,1)' I could not find any warning that gave an expected vs received quantity So, after skimming a list of messages from perldiag with descriptions Too many arguments in printf (expected 4, got 7) at [...] Substitute “sprintf” when that is being called. I don’t know if it’s possible to replace the silly one-for-each warning (It would be OK for my use if the same warnings category silences both Regards, |
From @avarOn Sun, Jan 19, 2014 at 9:17 AM, Aristotle Pagaltzis via RT
(I accidentally replied to the wrong mail and my initial reply opened I've pushed the avar/printf-too-many-arguments branch to perl5.git http://perl5.git.perl.org/perl.git/commitdiff/c299833c0ba6b2c1a04c7b98df90305d4d72b02d I did some experimentation on splitting up the "all" warning category But I haven't gotten that working yet. Here's the WIP patch for that: http://perl5.git.perl.org/perl.git/commitdiff/21781e853aa567a1e7c75462f3912a4ef1c4d7db In the process of implementing this I also made a new "missing" http://perl5.git.perl.org/perl.git/commitdiff/d4e7a8a601922309865854af2ebc7cd826fcd9ac Before it was piggy-backing on the "uninitialized" category. I'm It would "break" (for some value of) "no warnings qw(uninitalized)" on |
From perl5-porters@perl.orgavar at cpan.org wrote:
That is not nice.
I would prefer that a change like that be merged as early on in the |
From @tonycozOn Sat, Jan 18, 2014 at 08:16:37PM +0000, Dave Mitchell wrote:
+1 Tony |
From @rjbs* Dave Mitchell <davem@iabyn.com> [2014-01-18T15:16:37]
I agree happily with the first part and reluctantly with the second. New -- |
From @demerphqOn 20 January 2014 02:01, Ricardo Signes <perl.p5p@rjbs.manxome.org> wrote:
FWIW I am against this change in general. I think it adds a bad IMO it breaks one of the key things that to me makes Perl perlish, Larry set up the rules for Perl to be very tolerant of what the user Having said all that I would be ok with enabling it optionally tho, as BTW, a logical extreme extension of this patch sequence would be to print sprintf "%s %d", "foo", 2, "more string"; IOW, sprintf would know we only want two arguments, and only consume cheers, |
From @AbigailOn Mon, Jan 20, 2014 at 01:22:53PM +0100, demerphq wrote:
I agree with this.
Same here.
A sub with a prototype of ($$) doesn't "only consume" two from the list #!/usr/bin/perl use 5.010; use strict; sub two_args ($$) { sub many_args { many_args two_args "foo", "bar", "baz"; __END__ so if you want the sprintf in print sprintf "%s %d", "foo", 2, "more string"; behave as a ($$) prototypes sub, it ought to die. Unless you're suggesting It's only ($) that is special cased: #!/usr/bin/perl use 5.010; use strict; sub one_arg ($) { sub many_args { many_args one_arg "foo", "bar", "baz"; __END__ Abigail |
From @rjbs* demerphq <demerphq@gmail.com> [2014-01-20T07:22:53]
Nothing else other than printf, already? -- |
From @demerphqOn 20 January 2014 13:43, Abigail <abigail@abigail.be> wrote:
Doh. Thanks, you are right, I confused the behavior of ( Yves -- |
From @avarOn Mon, Jan 20, 2014 at 1:50 PM, Ricardo Signes
I'd (obviously) like this warning included. But to reply to Yves and Warnings aren't errors because they're recoverable, so they're code $ perl -wle 'my @kbd_toprow = qw[ ! @ # $ % ^ & * ( ) { } ]' I think one of the main problems with warnings now is that you can't Sometimes this is a good thing, but you get into the value judgement Personally I think that this particular warning should be on by What I was trying to (but have currently failed) to address in I'd like for warnings.pm to change so that it could have "extra", use warnings; Implicitly mean something like: use warnings (exists $ENV{DEFAULT_WARN_CATEGORIES} ? split /,/, Or better yet some global callback mechanism so you could selectively But aside from that I think that rather than engaging in subjective |
From @demerphqOn 20 January 2014 13:50, Ricardo Signes <perl.p5p@rjbs.manxome.org> wrote:
That was added without me noticing and is a regression that IMO should cheers, -- |
From @demerphqOn 20 January 2014 15:27, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
Useful analysis, thanks. I agree that the core problem here is not the Yves -- |
From @rjbs* Ævar Arnfjörð Bjarmason <avarab@gmail.com> [2014-01-20T09:27:40]
I agree with this and the rest of your post. -- |
From @pjcjOn Sun, Jan 19, 2014 at 09:57:15PM +0100, Ævar Arnfjörð Bjarmason wrote:
In this diff, you write: + # Tests for format parameter indexes. I think you have made the correct decision here. In the presence of state $fmt = { sprintf $fmt->{$res}, $Y, $M, $D, $h, $m I'd be happy to see your nice comment rewritten to be completely -- |
From @ikegamiOn Fri, Jan 17, 2014 at 7:26 PM, James E Keenan via RT <
C's printf tends to segfaults if you give the wrong number of arguments |
From @ikegamiOn Wed, Jan 22, 2014 at 9:52 AM, Eric Brine <ikegami@adaelis.com> wrote:
Ah yes, variable formats and positional arguments make it likely the |
From @avarOn lau 18 jan 12:16:52 2014, davem wrote:
I've just pushed the patch to split up the "missing" category in 3664866, and the patch to add warnings about redundant printf arguments in 4077a6b. We don't have any support for splitting out "extra" warning as discussed in this thread, a friend of mine picked up my patch series for that in https://github.com/andreasgudmundsson/perl5/commits/avar/printf-too-many-arguments and made it work, but I haven't yet reviewed it in any detail. In any case I don't have a use case for any new warning that isn't part of "all", although depending on how 4077a6b smokes on the CPAN we might want to split it out into such a category. |
@avar - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#121025 (status was 'resolved')
Searchable as RT121025$
The text was updated successfully, but these errors were encountered: