From 26f46ef26ba74cffce1d6c8336187f36af1b1e69 Mon Sep 17 00:00:00 2001 From: Jorg Sowa Date: Wed, 7 May 2025 22:48:32 +0200 Subject: [PATCH] refactor: ext md5 --- ext/standard/md5.c | 19 +++++++------------ ext/standard/md5.h | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/ext/standard/md5.c b/ext/standard/md5.c index 899ff6aaeecb0..9d0f5f886a6bb 100644 --- a/ext/standard/md5.c +++ b/ext/standard/md5.c @@ -19,32 +19,29 @@ #include "php.h" #include "md5.h" -PHPAPI void make_digest(char *md5str, const unsigned char *digest) /* {{{ */ +PHPAPI void make_digest(char *md5str, const unsigned char *digest) { make_digest_ex(md5str, digest, 16); } -/* }}} */ -PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, int len) /* {{{ */ +PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, size_t len) { static const char hexits[17] = "0123456789abcdef"; - int i; - for (i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { md5str[i * 2] = hexits[digest[i] >> 4]; md5str[(i * 2) + 1] = hexits[digest[i] & 0x0F]; } md5str[len * 2] = '\0'; } -/* }}} */ -/* {{{ Calculate the md5 hash of a string */ +/* Calculate the md5 hash of a string */ PHP_FUNCTION(md5) { zend_string *arg; - bool raw_output = 0; PHP_MD5_CTX context; unsigned char digest[16]; + bool raw_output = false; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(arg) @@ -63,14 +60,13 @@ PHP_FUNCTION(md5) } } -/* }}} */ -/* {{{ Calculate the md5 hash of given filename */ +/* Calculate the md5 hash of given filename */ PHP_FUNCTION(md5_file) { char *arg; size_t arg_len; - bool raw_output = 0; + bool raw_output = false; unsigned char buf[1024]; unsigned char digest[16]; PHP_MD5_CTX context; @@ -113,7 +109,6 @@ PHP_FUNCTION(md5_file) make_digest_ex(Z_STRVAL_P(return_value), digest, 16); } } -/* }}} */ /* * This is an OpenSSL-compatible implementation of the RSA Data Security, diff --git a/ext/standard/md5.h b/ext/standard/md5.h index c488b5c534e36..5444abf46aec6 100644 --- a/ext/standard/md5.h +++ b/ext/standard/md5.h @@ -19,7 +19,7 @@ #define MD5_H PHPAPI void make_digest(char *md5str, const unsigned char *digest); -PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, int len); +PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, size_t len); /* * This is an OpenSSL-compatible implementation of the RSA Data Security,