com php-src: Warnings become errors hash_init: ext/hash/h ash.c ext/hash/tests/hash_init_error.phpt
| From: | Joe Watkins | Date: | Thu, 29 Aug 2019 14:09:29 +0000 |
| Subject: | com php-src: Warnings become errors hash_init: ext/hash/h ash.c ext/hash/tests/hash_init_error.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-108136@lists.php.net to get a copy of this message | ||
Commit: 14c07fef748126d634a5ef8115cf5f72b8903811
Author: Mark <mrandall@digitellinc.com> Mon, 26 Aug 2019 22:52:45 +0100
Committer: Joe Watkins <krakjoe@php.net> Thu, 29 Aug 2019 16:09:29 +0200
Parents: 21587854b437db14db7e4d601421d2c7702afe4f
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=14c07fef748126d634a5ef8115cf5f72b8903811
Log:
Warnings become errors hash_init
Changed paths:
M ext/hash/hash.c
M ext/hash/tests/hash_init_error.phpt
Diff:
diff --git a/ext/hash/hash.c b/ext/hash/hash.c
index e9cc5bf..82c27af 100644
--- a/ext/hash/hash.c
+++ b/ext/hash/hash.c
@@ -358,19 +358,19 @@ PHP_FUNCTION(hash_init)
ops = php_hash_fetch_ops(ZSTR_VAL(algo), ZSTR_LEN(algo));
if (!ops) {
- php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", ZSTR_VAL(algo));
- RETURN_FALSE;
+ zend_throw_error(NULL, "Unknown hashing algorithm: %s", ZSTR_VAL(algo));
+ return;
}
if (options & PHP_HASH_HMAC) {
if (!ops->is_crypto) {
- php_error_docref(NULL, E_WARNING, "HMAC requested with a non-cryptographic hashing
algorithm: %s", ZSTR_VAL(algo));
- RETURN_FALSE;
+ zend_throw_error(NULL, "HMAC requested with a non-cryptographic hashing algorithm:
%s", ZSTR_VAL(algo));
+ return;
}
if (!key || (ZSTR_LEN(key) == 0)) {
/* Note: a zero length key is no key at all */
- php_error_docref(NULL, E_WARNING, "HMAC requested without a key");
- RETURN_FALSE;
+ zend_throw_error(NULL, "HMAC requested without a key");
+ return;
}
}
diff --git a/ext/hash/tests/hash_init_error.phpt b/ext/hash/tests/hash_init_error.phpt
index 9105b96..a68a8fc 100644
--- a/ext/hash/tests/hash_init_error.phpt
+++ b/ext/hash/tests/hash_init_error.phpt
@@ -4,30 +4,48 @@ Hash: hash_init() function - errors test
<?php
echo "*** Testing hash_init(): error conditions ***\n";
-echo "-- Testing hash_init() function with unknown algorithms --\n";
-var_dump(hash_init('dummy'));
+echo "\n-- Testing hash_init() function with unknown algorithms --\n";
+try {
+ var_dump(hash_init('dummy'));
+}
+catch (\Error $e) {
+ echo $e->getMessage() . "\n";
+}
+
+echo "\n-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms
--\n";
+try {
+ var_dump(hash_init('crc32', HASH_HMAC));
+}
+catch (\Error $e) {
+ echo $e->getMessage() . "\n";
+}
+
+echo "\n-- Testing hash_init() function with HASH_HMAC and no key --\n";
+try {
+ var_dump(hash_init('md5', HASH_HMAC));
+}
+catch (\Error $e) {
+ echo $e->getMessage() . "\n";
+}
+
+try {
+ var_dump(hash_init('md5', HASH_HMAC, null));
+}
+catch (\Error $e) {
+ echo $e->getMessage() . "\n";
+}
-echo "-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms
--\n";
-var_dump(hash_init('crc32', HASH_HMAC));
-echo "-- Testing hash_init() function with HASH_HMAC and no key --\n";
-var_dump(hash_init('md5', HASH_HMAC));
-var_dump(hash_init('md5', HASH_HMAC, null));
?>
---EXPECTF--
+--EXPECT--
*** Testing hash_init(): error conditions ***
+
-- Testing hash_init() function with unknown algorithms --
+Unknown hashing algorithm: dummy
-Warning: hash_init(): Unknown hashing algorithm: dummy in %s on line %d
-bool(false)
-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms --
+HMAC requested with a non-cryptographic hashing algorithm: crc32
-Warning: hash_init(): HMAC requested with a non-cryptographic hashing algorithm: crc32 in %s on
line %d
-bool(false)
-- Testing hash_init() function with HASH_HMAC and no key --
-
-Warning: hash_init(): HMAC requested without a key %s on line %d
-bool(false)
-
-Warning: hash_init(): HMAC requested without a key %s on line %d
-bool(false)
+HMAC requested without a key
+HMAC requested without a key