]> granicus.if.org Git - php/commitdiff
- Fix bug #37176 (iconv_strpos() fails to find a string)
authorMoriyoshi Koizumi <moriyoshi@php.net>
Thu, 27 Apr 2006 00:49:17 +0000 (00:49 +0000)
committerMoriyoshi Koizumi <moriyoshi@php.net>
Thu, 27 Apr 2006 00:49:17 +0000 (00:49 +0000)
ext/iconv/iconv.c
ext/iconv/tests/bug37176.phpt [new file with mode: 0644]

index ce3464624d2d126a9abc4a150dedc438eafcd9f2..de5b548027f905396903f604da2d70c923c9360d 100644 (file)
@@ -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 (file)
index 0000000..3923dbd
--- /dev/null
@@ -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)