mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-06 09:01:13 +02:00
36760: more care with already unmetafied pattern trial strings
This commit is contained in:
parent
64061e504f
commit
faeb9555d3
2 changed files with 45 additions and 15 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2015-10-03 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||||
|
|
||||||
|
* 36760: Src/pattern.c: ensure we don't do anything untoward
|
||||||
|
with an already metafied pattern trial match.
|
||||||
|
|
||||||
2015-10-03 Mikael Magnusson <mikachu@gmail.com>
|
2015-10-03 Mikael Magnusson <mikachu@gmail.com>
|
||||||
|
|
||||||
* 36754: Functions/TCP/tcp_open, Functions/TCP/tcp_read,
|
* 36754: Functions/TCP/tcp_open, Functions/TCP/tcp_read,
|
||||||
|
|
|
@ -2022,6 +2022,39 @@ pattrystart(void)
|
||||||
errsfound = 0;
|
errsfound = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fix up string length stuff.
|
||||||
|
*
|
||||||
|
* If we call patallocstr() with "force" to set things up early, it's
|
||||||
|
* done there, else it's done in pattryrefs(). The reason for the
|
||||||
|
* difference is in the latter case we may not be relying on
|
||||||
|
* patallocstr() having an effect.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**/
|
||||||
|
static void
|
||||||
|
patmungestring(char **string, int *stringlen, int *unmetalenin)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Special signalling of empty tokenised string.
|
||||||
|
*/
|
||||||
|
if (*stringlen > 0 && **string == Nularg) {
|
||||||
|
(*string)++;
|
||||||
|
/*
|
||||||
|
* If we don't have an unmetafied length
|
||||||
|
* and need it (we may not) we'll get it later.
|
||||||
|
*/
|
||||||
|
if (*unmetalenin > 0)
|
||||||
|
(*unmetalenin)--;
|
||||||
|
if (*stringlen > 0)
|
||||||
|
(*stringlen)--;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ensure we have a metafied length */
|
||||||
|
if (*stringlen < 0)
|
||||||
|
*stringlen = strlen(*string);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate memeory for pattern match. Note this is specific to use
|
* Allocate memeory for pattern match. Note this is specific to use
|
||||||
* of pattern *and* trial string.
|
* of pattern *and* trial string.
|
||||||
|
@ -2039,7 +2072,8 @@ pattrystart(void)
|
||||||
* force is 1 if we always unmetafy: this is useful if we are going
|
* force is 1 if we always unmetafy: this is useful if we are going
|
||||||
* to try again with different versions of the string. If this is
|
* to try again with different versions of the string. If this is
|
||||||
* called from pattryrefs() we don't force unmetafication as it won't
|
* called from pattryrefs() we don't force unmetafication as it won't
|
||||||
* be optimal.
|
* be optimal. This option should be used if the resulting
|
||||||
|
* patstralloc is going to be passed to pattrylen() / pattryrefs().
|
||||||
* In patstralloc (supplied by caller, must last until last pattry is done)
|
* In patstralloc (supplied by caller, must last until last pattry is done)
|
||||||
* unmetalen is the unmetafied length of the string; it will be
|
* unmetalen is the unmetafied length of the string; it will be
|
||||||
* calculated if the input value is negative.
|
* calculated if the input value is negative.
|
||||||
|
@ -2056,6 +2090,9 @@ char *patallocstr(Patprog prog, char *string, int stringlen, int unmetalen,
|
||||||
{
|
{
|
||||||
int needfullpath;
|
int needfullpath;
|
||||||
|
|
||||||
|
if (force)
|
||||||
|
patmungestring(&string, &stringlen, &unmetalen);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For a top-level ~-exclusion, we will need the full
|
* For a top-level ~-exclusion, we will need the full
|
||||||
* path to exclude, so copy the path so far and append the
|
* path to exclude, so copy the path so far and append the
|
||||||
|
@ -2224,21 +2261,9 @@ pattryrefs(Patprog prog, char *string, int stringlen, int unmetalenin,
|
||||||
maxnpos = *nump;
|
maxnpos = *nump;
|
||||||
*nump = 0;
|
*nump = 0;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* Special signalling of empty tokenised string.
|
|
||||||
*/
|
|
||||||
if ((!patstralloc || stringlen > 0) && *string == Nularg) {
|
|
||||||
string++;
|
|
||||||
if (unmetalenin > 0)
|
|
||||||
unmetalenin--;
|
|
||||||
if (stringlen > 0)
|
|
||||||
stringlen--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stringlen < 0) {
|
if (!patstralloc)
|
||||||
DPUTS(patstralloc != NULL, "length needed with patstralloc");
|
patmungestring(&string, &stringlen, &unmetalenin);
|
||||||
stringlen = strlen(string);
|
|
||||||
}
|
|
||||||
origlen = stringlen;
|
origlen = stringlen;
|
||||||
|
|
||||||
if (patstralloc) {
|
if (patstralloc) {
|
||||||
|
|
Loading…
Reference in a new issue