summaryrefslogtreecommitdiff
path: root/ext/iconv/iconv.c
diff options
context:
space:
mode:
authorFrancois Laupretre <francois@tekwire.net>2015-12-24 19:03:10 +0100
committerNikita Popov <nikic@php.net>2016-03-09 14:41:38 +0100
commit570bbed98e54aaf132b97befb92689c96bdee687 (patch)
tree62e224232997aa1169b60290d26402de141c0fa0 /ext/iconv/iconv.c
parent4a8c51c7d7f28653203ed6e5d6c89e5e829c57a3 (diff)
downloadphp-git-570bbed98e54aaf132b97befb92689c96bdee687.tar.gz
Add negative offset support to iconv_strpos()
Diffstat (limited to 'ext/iconv/iconv.c')
-rw-r--r--ext/iconv/iconv.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index d4a7f6e0af..0d44936ea6 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -2121,7 +2121,7 @@ PHP_FUNCTION(iconv_substr)
PHP_FUNCTION(iconv_strpos)
{
char *charset = get_internal_encoding();
- size_t charset_len = 0;
+ size_t charset_len = 0, haystk_len;
zend_string *haystk;
zend_string *ndl;
zend_long offset = 0;
@@ -2142,8 +2142,17 @@ PHP_FUNCTION(iconv_strpos)
}
if (offset < 0) {
- php_error_docref(NULL, E_WARNING, "Offset not contained in string.");
- RETURN_FALSE;
+ /* Convert negative offset (counted from the end of string) */
+ err = _php_iconv_strlen(&haystk_len, ZSTR_VAL(haystk), ZSTR_LEN(haystk), charset);
+ if (err != PHP_ICONV_ERR_SUCCESS) {
+ _php_iconv_show_error(err, GENERIC_SUPERSET_NAME, charset);
+ RETURN_FALSE;
+ }
+ offset += haystk_len;
+ if (offset < 0) { /* If offset before start */
+ php_error_docref(NULL, E_WARNING, "Offset not contained in string.");
+ RETURN_FALSE;
+ }
}
if (ZSTR_LEN(ndl) < 1) {