]> granicus.if.org Git - php/commitdiff
Improve error messages of ext/zlib
authorMáté Kocsis <kocsismate@woohoolabs.com>
Wed, 17 Jun 2020 14:40:46 +0000 (16:40 +0200)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Wed, 17 Jun 2020 14:50:00 +0000 (16:50 +0200)
ext/zlib/tests/deflate_add_error.phpt
ext/zlib/tests/deflate_init_error.phpt
ext/zlib/tests/dictionary_usage.phpt
ext/zlib/tests/inflate_add_error.phpt
ext/zlib/zlib.c

index b2b7d7917c0f001a98d5d24c8ae78b871e60b642..4a467d39bfe983f8ae37c418e571ffc979b7fc2c 100644 (file)
@@ -27,5 +27,5 @@ try {
 
 ?>
 --EXPECT--
-deflate_add(): supplied resource is not a valid zlib deflate resource
-Flush mode must be ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK or ZLIB_FINISH
+deflate_add(): Argument #1 ($context) must be of type DeflateContext, resource given
+deflate_add(): Argument #3 ($flush_behavior) must be one of ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK, or ZLIB_FINISH
index be3f0974d65264cfb0c6d3773768ccc9f08bb67b..b31a16be9accf48275f39990df514739fa1f7b58 100644 (file)
@@ -41,8 +41,8 @@ try {
 
 ?>
 --EXPECT--
-Encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE
-Compression level (42) must be within -1..9
-Compression level (-2) must be within -1..9
-Compression memory level (0) must be within 1..9
-Compression memory level (10) must be within 1..9
+deflate_init(): Argument #1 ($encoding) must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE
+deflate_init(): "level" option must be between -1 and 9
+deflate_init(): "level" option must be between -1 and 9
+deflate_init(): "memory" option must be between 1 and 9
+deflate_init(): "memory" option must be between 1 and 9
index 195e9b216d5acd7cc981f47057cb5aef79ef9f79..359cfd3550eb4b0ec06602f2cd5924a198c95c21 100644 (file)
@@ -18,7 +18,6 @@ var_dump($dictStr_a === $a);
 $r = inflate_init(ZLIB_ENCODING_DEFLATE, ["dictionary" => $dict]);
 var_dump(inflate_add($r, $a, ZLIB_FINISH));
 
-
 $r = inflate_init(ZLIB_ENCODING_DEFLATE, ["dictionary" => ["8"] + range("a", "z")]);
 var_dump(inflate_add($r, $a, ZLIB_FINISH));
 
index 9622e5a4c40b8d2dae089b893bb5ead384ee420f..33792197523cd20d43a1f3703bbb5ab05829453d 100644 (file)
@@ -26,5 +26,5 @@ try {
 
 ?>
 --EXPECT--
-inflate_add(): supplied resource is not a valid zlib inflate resource
-Flush mode must be ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK or ZLIB_FINISH
+inflate_add(): Argument #1 ($context) must be of type InflateContext, resource given
+inflate_add(): Argument #3 ($flush_mode) must be one of ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK, or ZLIB_FINISH
index ae65ba439624bf4a92b5cef0f47533dbccaf2d12..11753b0f83965d0b2ece6f8a6a57cc57d8d5c414 100644 (file)
@@ -786,7 +786,7 @@ static zend_bool zlib_create_dictionary_string(HashTable *options, char **dict,
                                                        }
                                                        efree(strings);
                                                        if (!EG(exception)) {
-                                                               zend_value_error("Dictionary entries must be non-empty strings");
+                                                               zend_argument_value_error(2, "must not contain empty strings");
                                                        }
                                                        return 0;
                                                }
@@ -796,7 +796,7 @@ static zend_bool zlib_create_dictionary_string(HashTable *options, char **dict,
                                                                        efree(ptr);
                                                                } while (--ptr >= strings);
                                                                efree(strings);
-                                                               zend_value_error("Dictionary entries must not contain a NULL-byte");
+                                                               zend_argument_value_error(2, "must not contain strings with null bytes");
                                                                return 0;
                                                        }
                                                }
@@ -1077,7 +1077,7 @@ PHP_FUNCTION(deflate_init)
                level = zval_get_long(option_buffer);
        }
        if (level < -1 || level > 9) {
-               zend_value_error("Compression level (" ZEND_LONG_FMT ") must be within -1..9", level);
+               zend_value_error("deflate_init(): \"level\" option must be between -1 and 9");
                RETURN_THROWS();
        }
 
@@ -1085,7 +1085,7 @@ PHP_FUNCTION(deflate_init)
                memory = zval_get_long(option_buffer);
        }
        if (memory < 1 || memory > 9) {
-               zend_value_error("Compression memory level (" ZEND_LONG_FMT ") must be within 1..9", memory);
+               zend_value_error("deflate_init(): \"memory\" option must be between 1 and 9");
                RETURN_THROWS();
        }
 
@@ -1093,7 +1093,7 @@ PHP_FUNCTION(deflate_init)
                window = zval_get_long(option_buffer);
        }
        if (window < 8 || window > 15) {
-               zend_value_error("zlib window size (logarithm) (" ZEND_LONG_FMT ") must be within 8..15", window);
+               zend_value_error("deflate_init(): \"window\" option must be between 8 and 15");
                RETURN_THROWS();
        }
 
@@ -1108,7 +1108,7 @@ PHP_FUNCTION(deflate_init)
                case Z_DEFAULT_STRATEGY:
                        break;
                default:
-                       zend_value_error("Strategy must be one of ZLIB_FILTERED, ZLIB_HUFFMAN_ONLY, ZLIB_RLE, ZLIB_FIXED or ZLIB_DEFAULT_STRATEGY");
+                       zend_value_error("deflate_init(): \"strategy\" option must be one of ZLIB_FILTERED, ZLIB_HUFFMAN_ONLY, ZLIB_RLE, ZLIB_FIXED or ZLIB_DEFAULT_STRATEGY");
                        RETURN_THROWS();
        }
 
@@ -1122,7 +1122,7 @@ PHP_FUNCTION(deflate_init)
                case PHP_ZLIB_ENCODING_DEFLATE:
                        break;
                default:
-                       zend_value_error("Encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE");
+                       zend_argument_value_error(1, "must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE");
                        RETURN_THROWS();
        }
 
@@ -1186,8 +1186,7 @@ PHP_FUNCTION(deflate_add)
                        break;
 
                default:
-                       zend_value_error(
-                               "Flush mode must be ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK or ZLIB_FINISH");
+                       zend_argument_value_error(3, "must be one of ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK, or ZLIB_FINISH");
                        RETURN_THROWS();
        }