summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoriyoshi Koizumi <moriyoshi@php.net>2006-04-27 00:50:54 +0000
committerMoriyoshi Koizumi <moriyoshi@php.net>2006-04-27 00:50:54 +0000
commit522ce80071e992132f549bd5dd41de43f50ccc55 (patch)
tree65d85279e1f1d8d80073971a5c498d5306b9491d
parente0beb7fc717065ddca39a903cff825f48eef1bae (diff)
downloadphp-git-522ce80071e992132f549bd5dd41de43f50ccc55.tar.gz
- MFH: fix bug #37176 (iconv_strpos() fails to find a string)
-rw-r--r--ext/iconv/iconv.c32
-rw-r--r--ext/iconv/tests/bug37176.phpt10
2 files changed, 24 insertions, 18 deletions
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 4c78ac022f..6b7c483759 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -822,18 +822,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 {
@@ -867,18 +865,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--
+<?php
+var_dump(iconv_strpos('11--','1-',0,'UTF-8'));
+var_dump(iconv_strpos('-11--','1-',0,'UTF-8'));
+?>
+--EXPECT--
+int(1)
+int(2)