GNU bug report logs - #67841
[PATCH] Clarify error messages for misuse of m4_warn and --help for -W.

Previous Next

Package: automake-patches;

Reported by: Zack Weinberg <zack <at> owlfolio.org>

Date: Fri, 15 Dec 2023 20:45:02 UTC

Severity: normal

Tags: patch

Done: Karl Berry <karl <at> freefriends.org>

Bug is archived. No further changes may be made.

Full log


Message #11 received at 67841 <at> debbugs.gnu.org (full text, mbox):

From: Jacob Bachmeyer <jcb62281 <at> gmail.com>
To: Zack Weinberg <zack <at> owlfolio.org>
Cc: autoconf-patches <at> gnu.org, 67841 <at> debbugs.gnu.org
Subject: Re: [bug#67841] [PATCH] Clarify error messages for misuse of m4_warn
 and --help for -W.
Date: Fri, 15 Dec 2023 18:08:00 -0600
Zack Weinberg wrote:
> [...]
>
> Since this touches code shared between Autoconf and Automake, I’m not
> checking it in yet and I’m requesting comments from both sides of the
> fence.  Also, there’s a perl 2.14ism in one place (s///a) which I need
> to figure out how to make 2.6-compatible before it can land.
>
> [...]
>  
> +sub report_bad_channel ($$)
> +{
> +  my ($channel, $location) = @_;
> +  my $message;
> +  my $report_as = 'error';
> +
> +  # quotemeta is both too aggressive (e.g. it escapes '-') and
> +  # too generous (it turns control characters into \ + themselves,
> +  # not into symbolic escapes).
> +  my $q_channel = $channel;
> +  $q_channel =~ s/\\/\\\\/g;
> +  $q_channel =~ s/([^\x20-\x7e])/"\\x".sprintf("%02x", ord($1))/aeg;
> +  $q_channel =~ s/(?=[\"\$\'\@\`])/\\/g;
> +  $q_channel = '"' . $q_channel . '"';
>
> [...]
>   

If I am reading perlre correctly, you should be able to simply drop the 
/a modifier because it has no effect on the pattern you have written, 
since you are using an explicit character class and are *not* using the 
/i modifier.  (The documentation says that /a only affects the \d, \s, 
\w Perl character classes and the POSIX character classes.)  Further, 
Perl's sprintf is indeed sprintf, so you should be able to rewrite that 
substitution as:

s/([^\x20-\x7e])/sprintf('\\x%02x', ord $1)/eg


This slightly simplifies the program (eliminating one concatenation), 
which is probably of trivial consequence, since this code is on an error 
path and not an inner loop.  More importantly, including the "\\x" in 
the sprintf format string makes the intended output more clear.  The 
single quotes are both a (very slight) performance optimization and 
serve to document that no direct interpolation is intended because this 
is a format string.  Perl's handling of backslash in single quotes is 
fun:  backslash escapes itself but will also be taken literally if it 
does not form an escape that is allowed in q[].


-- Jacob




This bug report was last modified 1 year and 151 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.