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

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

index 7df2240f95a707a14d95c8251b1a86d33daaf0bf..832d2dca76f6b26e2d3052b01a337d4c123ea7c8 100644 (file)
@@ -809,7 +809,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;
                }
 
@@ -827,10 +829,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