From 923978e0ff48c4adb82d570b29e93c599f9ecb83 Mon Sep 17 00:00:00 2001 From: Moriyoshi Koizumi Date: Thu, 27 Apr 2006 00:49:17 +0000 Subject: [PATCH] - Fix bug #37176 (iconv_strpos() fails to find a string) --- ext/iconv/iconv.c | 33 +++++++++++++++------------------ ext/iconv/tests/bug37176.phpt | 10 ++++++++++ 2 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 ext/iconv/tests/bug37176.phpt diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index ce3464624d..de5b548027 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -797,6 +797,7 @@ static php_iconv_err_t _php_iconv_strpos(unsigned int *pretval, } if (offset >= 0) { if (cnt >= (unsigned int)offset) { + fprintf(stderr, "%s %s\n", ndl_buf_p, buf); if (_php_iconv_memequal(buf, ndl_buf_p, sizeof(buf))) { if (match_ofs == (unsigned int)-1) { match_ofs = cnt; @@ -825,18 +826,16 @@ static php_iconv_err_t _php_iconv_strpos(unsigned int *pretval, j += GENERIC_SUPERSET_NBYTES; } - if (!_php_iconv_memequal(buf, &ndl_buf[i], sizeof(buf))) { - i = 0; - } - - if (i == 0) { - match_ofs = (unsigned int)-1; - } else { + if (_php_iconv_memequal(buf, &ndl_buf[i], sizeof(buf))) { match_ofs += (lim - i) / GENERIC_SUPERSET_NBYTES; i += GENERIC_SUPERSET_NBYTES; + ndl_buf_p = &ndl_buf[i]; + ndl_buf_left = ndl_buf_len - i; + } else { + match_ofs = (unsigned int)-1; + ndl_buf_p = ndl_buf; + ndl_buf_left = ndl_buf_len; } - ndl_buf_p = &ndl_buf[i]; - ndl_buf_left = ndl_buf_len - i; } } } else { @@ -870,18 +869,16 @@ static php_iconv_err_t _php_iconv_strpos(unsigned int *pretval, j += GENERIC_SUPERSET_NBYTES; } - if (!_php_iconv_memequal(buf, &ndl_buf[i], sizeof(buf))) { - i = 0; - } - - if (i == 0) { - match_ofs = (unsigned int)-1; - } else { + if (_php_iconv_memequal(buf, &ndl_buf[i], sizeof(buf))) { match_ofs += (lim - i) / GENERIC_SUPERSET_NBYTES; i += GENERIC_SUPERSET_NBYTES; + ndl_buf_p = &ndl_buf[i]; + ndl_buf_left = ndl_buf_len - i; + } else { + match_ofs = (unsigned int)-1; + ndl_buf_p = ndl_buf; + ndl_buf_left = ndl_buf_len; } - ndl_buf_p = &ndl_buf[i]; - ndl_buf_left = ndl_buf_len - i; } } } diff --git a/ext/iconv/tests/bug37176.phpt b/ext/iconv/tests/bug37176.phpt new file mode 100644 index 0000000000..3923dbd49c --- /dev/null +++ b/ext/iconv/tests/bug37176.phpt @@ -0,0 +1,10 @@ +--TEST-- +Bug #37176 (iconv_strpos() fails to find a string) +--FILE-- + +--EXPECT-- +int(1) +int(2) -- 2.50.1