diff options
author | Francois Laupretre <francois@tekwire.net> | 2016-01-04 16:31:52 +0100 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2016-03-09 14:41:38 +0100 |
commit | 882f97042b55d8f7d3c50f453c56b984334247f2 (patch) | |
tree | 641f4804c6e24e39ef17de3492e1f8a1c993bb0a /ext/mbstring/php_mbregex.c | |
parent | 70187267b451c71fd6da89117565578ae6f71a2f (diff) | |
download | php-git-882f97042b55d8f7d3c50f453c56b984334247f2.tar.gz |
mb_ereg_search_setpos(): Add support for negative position
Also add missing test for this function
Diffstat (limited to 'ext/mbstring/php_mbregex.c')
-rw-r--r-- | ext/mbstring/php_mbregex.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index 1bd26d7334..6a9ab193af 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -1400,6 +1400,11 @@ PHP_FUNCTION(mb_ereg_search_setpos) return; } + /* Accept negative position if length of search string can be determined */ + if ((position < 0) && (!Z_ISUNDEF(MBREX(search_str))) && (Z_TYPE(MBREX(search_str)) == IS_STRING)) { + position += Z_STRLEN(MBREX(search_str)); + } + if (position < 0 || (!Z_ISUNDEF(MBREX(search_str)) && Z_TYPE(MBREX(search_str)) == IS_STRING && (size_t)position >= Z_STRLEN(MBREX(search_str)))) { php_error_docref(NULL, E_WARNING, "Position is out of range"); MBREX(search_pos) = 0; |