From 1efaed7cf7f112fa9c5920626084e8a36b6af781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Wed, 17 Jun 2020 16:40:46 +0200 Subject: Improve error messages of ext/zlib --- ext/zlib/tests/deflate_add_error.phpt | 4 ++-- ext/zlib/tests/deflate_init_error.phpt | 10 +++++----- ext/zlib/tests/dictionary_usage.phpt | 1 - ext/zlib/tests/inflate_add_error.phpt | 4 ++-- ext/zlib/zlib.c | 17 ++++++++--------- 5 files changed, 17 insertions(+), 19 deletions(-) (limited to 'ext/zlib') diff --git a/ext/zlib/tests/deflate_add_error.phpt b/ext/zlib/tests/deflate_add_error.phpt index b2b7d7917c..4a467d39bf 100644 --- a/ext/zlib/tests/deflate_add_error.phpt +++ b/ext/zlib/tests/deflate_add_error.phpt @@ -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 diff --git a/ext/zlib/tests/deflate_init_error.phpt b/ext/zlib/tests/deflate_init_error.phpt index be3f0974d6..b31a16be9a 100644 --- a/ext/zlib/tests/deflate_init_error.phpt +++ b/ext/zlib/tests/deflate_init_error.phpt @@ -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 diff --git a/ext/zlib/tests/dictionary_usage.phpt b/ext/zlib/tests/dictionary_usage.phpt index 195e9b216d..359cfd3550 100644 --- a/ext/zlib/tests/dictionary_usage.phpt +++ b/ext/zlib/tests/dictionary_usage.phpt @@ -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)); diff --git a/ext/zlib/tests/inflate_add_error.phpt b/ext/zlib/tests/inflate_add_error.phpt index 9622e5a4c4..3379219752 100644 --- a/ext/zlib/tests/inflate_add_error.phpt +++ b/ext/zlib/tests/inflate_add_error.phpt @@ -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 diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index ae65ba4396..11753b0f83 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -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(); } -- cgit v1.2.1