]> granicus.if.org Git - php/commitdiff
Fixed bug #37773 (iconv_substr() gives "Unknown error" when string length =
authorIlia Alshanetsky <iliaa@php.net>
Wed, 15 Nov 2006 18:34:57 +0000 (18:34 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 15 Nov 2006 18:34:57 +0000 (18:34 +0000)
1").

NEWS
ext/iconv/iconv.c
ext/iconv/tests/bug37773.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 9b6f91436ff73e7ac25747062b3ce3e7bec5e5e9..e161130ce2ca616055402c16cb4131927a9399aa 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -81,6 +81,8 @@ PHP                                                                        NEWS
   (Dmitry)
 - Fixed bug #38456 (Apache2 segfaults when virtual() is called in .php
   ErrorDocument). (Ilia)
+- Fixed bug #37773 (iconv_substr() gives "Unknown error" when string length = 1").
+  (Ilia)
 - Fixed bug #36975 (natcasesort() causes array_pop() to misbehave). (Hannes)
 - Fixed bug #36812 (pg_execute() modifies input array). (Ilia)
 - Fixed bug #36644 (possible crash in variant_date_from_timestamp()). (Ilia)
index 492157024d6f4b1ea0d78115cb111233f1e6529a..e6840e8f41f4e11f50e05d8d06fef4372f4bbf01 100644 (file)
@@ -744,7 +744,9 @@ static php_iconv_err_t _php_iconv_substr(smart_str *pretval,
                                }
                        }
 
-                       _php_iconv_appendl(pretval, buf, sizeof(buf), cd2);
+                       if (_php_iconv_appendl(pretval, buf, sizeof(buf), cd2) != PHP_ICONV_ERR_SUCCESS) {
+                               break;
+                       }
                        --len;
                }
 
@@ -762,10 +764,6 @@ static php_iconv_err_t _php_iconv_substr(smart_str *pretval,
 
                case E2BIG:
                        break;
-
-               default:
-                       err = PHP_ICONV_ERR_UNKNOWN;
-                       break;
        }
 #endif
        if (err == PHP_ICONV_ERR_SUCCESS) {
diff --git a/ext/iconv/tests/bug37773.phpt b/ext/iconv/tests/bug37773.phpt
new file mode 100644 (file)
index 0000000..f55c153
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Bug #37773 (iconv_substr() gives "Unknown error" when string length = 1")
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--FILE--
+<?php
+       var_dump(iconv_substr('x', 0, 1, 'UTF-8'));
+?>
+--EXPECT--
+string(1) "x"
\ No newline at end of file