diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2002-09-24 16:34:54 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2002-09-24 16:34:54 +0000 |
commit | f91b3d5c6d4bedb87e57759d806e751de68f6173 (patch) | |
tree | 564f3624384137145578de43c545a35c9195fc4a /ext/ereg | |
parent | 5f1bffe0cd3fd6136baafed2d0b39306d7881c8b (diff) | |
download | php-git-f91b3d5c6d4bedb87e57759d806e751de68f6173.tar.gz |
Fixed bug #17957
Diffstat (limited to 'ext/ereg')
-rw-r--r-- | ext/ereg/ereg.c | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/ext/ereg/ereg.c b/ext/ereg/ereg.c index 9b8513e380..6d67f17e40 100644 --- a/ext/ereg/ereg.c +++ b/ext/ereg/ereg.c @@ -20,6 +20,7 @@ /* $Id$ */ #include <stdio.h> +#include <ctype.h> #include "php.h" #include "php_string.h" #include "reg.h" @@ -340,13 +341,10 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha new_l = strlen(buf) + subs[0].rm_so; /* part before the match */ walk = replace; while (*walk) - if ('\\' == *walk - && '0' <= walk[1] && '9' >= walk[1] - && walk[1] - '0' <= ((char) re.re_nsub) - && subs[walk[1] - '0'].rm_so > -1 - && subs[walk[1] - '0'].rm_eo > -1) { - new_l += subs[walk[1] - '0'].rm_eo - - subs[walk[1] - '0'].rm_so; + if ('\\' == *walk && isdigit(walk[1]) && walk[1] - '0' <= ((char) re.re_nsub)) { + if (subs[walk[1] - '0'].rm_so > -1 && subs[walk[1] - '0'].rm_eo > -1) { + new_l += subs[walk[1] - '0'].rm_eo - subs[walk[1] - '0'].rm_so; + } walk += 2; } else { new_l++; @@ -368,22 +366,19 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha walkbuf = &buf[tmp + subs[0].rm_so]; walk = replace; while (*walk) - if ('\\' == *walk - && '0' <= walk[1] && '9' >= walk[1] - && walk[1] - '0' <= re.re_nsub - && subs[walk[1] - '0'].rm_so > -1 - && subs[walk[1] - '0'].rm_eo > -1 - /* this next case shouldn't happen. it does. */ - && subs[walk[1] - '0'].rm_so <= subs[walk[1] - '0'].rm_eo) { - tmp = subs[walk[1] - '0'].rm_eo - - subs[walk[1] - '0'].rm_so; - memcpy (walkbuf, - &string[pos + subs[walk[1] - '0'].rm_so], - tmp); - walkbuf += tmp; + if ('\\' == *walk && isdigit(walk[1]) && walk[1] - '0' <= re.re_nsub) { + if (subs[walk[1] - '0'].rm_so > -1 && subs[walk[1] - '0'].rm_eo > -1 + /* this next case shouldn't happen. it does. */ + && subs[walk[1] - '0'].rm_so <= subs[walk[1] - '0'].rm_eo) { + + tmp = subs[walk[1] - '0'].rm_eo - subs[walk[1] - '0'].rm_so; + memcpy (walkbuf, &string[pos + subs[walk[1] - '0'].rm_so], tmp); + walkbuf += tmp; + } walk += 2; - } else + } else { *walkbuf++ = *walk++; + } *walkbuf = '\0'; /* and get ready to keep looking for replacements */ |