com php-src: Warnings to Errors hash_equals: ext/hash/has h.c ext/hash/tests/hash_equals.phpt
| From: | Joe Watkins | Date: | Thu, 29 Aug 2019 14:13:06 +0000 |
| Subject: | com php-src: Warnings to Errors hash_equals: ext/hash/has h.c ext/hash/tests/hash_equals.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-108138@lists.php.net to get a copy of this message | ||
Commit: 1f863399d539b1bb090c281a4b9e04209540be6b
Author: Mark <mrandall@digitellinc.com> Mon, 26 Aug 2019 23:44:20 +0100
Committer: Joe Watkins <krakjoe@php.net> Thu, 29 Aug 2019 16:13:06 +0200
Parents: e18bac96b70d37ccfdead11b7c465a75401c58bb
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1f863399d539b1bb090c281a4b9e04209540be6b
Log:
Warnings to Errors hash_equals
Changed paths:
M ext/hash/hash.c
M ext/hash/tests/hash_equals.phpt
Diff:
diff --git a/ext/hash/hash.c b/ext/hash/hash.c
index 8a9485c..f968daf 100644
--- a/ext/hash/hash.c
+++ b/ext/hash/hash.c
@@ -864,13 +864,13 @@ PHP_FUNCTION(hash_equals)
/* We only allow comparing string to prevent unexpected results. */
if (Z_TYPE_P(known_zval) != IS_STRING) {
- php_error_docref(NULL, E_WARNING, "Expected known_string to be a string, %s given",
zend_zval_type_name(known_zval));
- RETURN_FALSE;
+ zend_type_error("Expected known_string to be a string, %s given",
zend_zval_type_name(known_zval));
+ return;
}
if (Z_TYPE_P(user_zval) != IS_STRING) {
- php_error_docref(NULL, E_WARNING, "Expected user_string to be a string, %s given",
zend_zval_type_name(user_zval));
- RETURN_FALSE;
+ zend_type_error("Expected user_string to be a string, %s given",
zend_zval_type_name(user_zval));
+ return;
}
if (Z_STRLEN_P(known_zval) != Z_STRLEN_P(user_zval)) {
diff --git a/ext/hash/tests/hash_equals.phpt b/ext/hash/tests/hash_equals.phpt
index 0c8ab42..1716d3b 100644
--- a/ext/hash/tests/hash_equals.phpt
+++ b/ext/hash/tests/hash_equals.phpt
@@ -2,21 +2,36 @@
Hash: hash_equals() test
--FILE--
<?php
-var_dump(hash_equals("same", "same"));
-var_dump(hash_equals("not1same", "not2same"));
-var_dump(hash_equals("short", "longer"));
-var_dump(hash_equals("longer", "short"));
-var_dump(hash_equals("", "notempty"));
-var_dump(hash_equals("notempty", ""));
-var_dump(hash_equals("", ""));
-var_dump(hash_equals(123, "NaN"));
-var_dump(hash_equals("NaN", 123));
-var_dump(hash_equals(123, 123));
-var_dump(hash_equals(null, ""));
-var_dump(hash_equals(null, 123));
-var_dump(hash_equals(null, null));
+
+function trycatch_dump(...$tests) {
+ foreach ($tests as $test) {
+ try {
+ var_dump($test());
+ }
+ catch (\Error $e) {
+ echo '[' . get_class($e) . '] ' . $e->getMessage() .
"\n";
+ }
+ }
+}
+
+trycatch_dump(
+ fn() => hash_equals("same", "same"),
+ fn() => hash_equals("not1same", "not2same"),
+ fn() => hash_equals("short", "longer"),
+ fn() => hash_equals("longer", "short"),
+ fn() => hash_equals("", "notempty"),
+ fn() => hash_equals("notempty", ""),
+ fn() => hash_equals("", ""),
+ fn() => hash_equals(123, "NaN"),
+ fn() => hash_equals("NaN", 123),
+ fn() => hash_equals(123, 123),
+ fn() => hash_equals(null, ""),
+ fn() => hash_equals(null, 123),
+ fn() => hash_equals(null, null),
+);
+
?>
---EXPECTF--
+--EXPECT--
bool(true)
bool(false)
bool(false)
@@ -24,21 +39,9 @@ bool(false)
bool(false)
bool(false)
bool(true)
-
-Warning: hash_equals(): Expected known_string to be a string, int given in %s on line %d
-bool(false)
-
-Warning: hash_equals(): Expected user_string to be a string, int given in %s on line %d
-bool(false)
-
-Warning: hash_equals(): Expected known_string to be a string, int given in %s on line %d
-bool(false)
-
-Warning: hash_equals(): Expected known_string to be a string, null given in %s on line %d
-bool(false)
-
-Warning: hash_equals(): Expected known_string to be a string, null given in %s on line %d
-bool(false)
-
-Warning: hash_equals(): Expected known_string to be a string, null given in %s on line %d
-bool(false)
+[TypeError] Expected known_string to be a string, int given
+[TypeError] Expected user_string to be a string, int given
+[TypeError] Expected known_string to be a string, int given
+[TypeError] Expected known_string to be a string, null given
+[TypeError] Expected known_string to be a string, null given
+[TypeError] Expected known_string to be a string, null given