NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: PR/57773 CVS commit: src/bin/sh
The following reply was made to PR bin/57773; it has been noted by GNATS.
From: Robert Elz <kre%munnari.OZ.AU@localhost>
To: Jarle Greipsland <jarle.greipsland%norid.no@localhost>
Cc: gnats-bugs%netbsd.org@localhost
Subject: Re: PR/57773 CVS commit: src/bin/sh
Date: Thu, 28 Dec 2023 12:47:23 +0700
Date: Wed, 27 Dec 2023 23:44:07 +0100 (CET)
From: Jarle Greipsland <jarle.greipsland%norid.no@localhost>
Message-ID: <20231227.234407.2096023211607554905.jarle%norid.no@localhost>
| There are however still some gremlins in the code wrt. to the
| escape characters. The string lengths are not always calculated
| correctly.
That turned out to be the exact opposite problem of the previous
one - the earlier one was failing to insert the CTLESC when it
turned out to be needed, this one is in inserting CTLESC chars
when they aren't wanted.
The ${#var} code is kind of special - it doesn't bother expanding
the value of var, it just counts the length, and inserts that.
That's kind of the obvious thing to do really. But for the
special parameters, that doesn't work, as most of them don't
have string values that can just be counted - they need to be
generated first. So, that gets done, and then the length of
the value produced is counted.
The issue here, is that the positional parameters are treated
as special params for this purpose ... they aren't stored in the
same way that variables are, so they cannot simply be treated
as vars, but they are all strings, so lengths could just be counted
without expanding them, as is done for vars. But that's not the
way the code has ever worked - it simply expands all of those,
specials and positional, and then determines the length of the
result of the expansion.
In the cases in the examples given, the ${#X} was always being
performed in a situation where CTSESC processing is nomally needed,
so that was being requested. The code that handles ${#...} was
turning off some of that - but not all of it, and in any case, the
flags were being ignored and CTLESC chars inserted ahead of any
CTL char anyway (all cases).
So two minor fixes will eventually happen when I am finished
testing (less this time, as it is clearer what is happening,
and that the fix is OK) - one to turn off all the "escaping needed"
flags in the ${#X} case, and one to make sure at least one of those
is on, before inserting CTLESC chars, always.
kre
Home |
Main Index |
Thread Index |
Old Index