Skip to content

Commit c6a9bee

Browse files
authored
ext/standard/md5: Minor refactorings (#18518)
- Use size_t type instead of int type - Use false instead of 0 - Remove wrapping comments
1 parent e3715cd commit c6a9bee

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

ext/standard/md5.c

+7-12
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,29 @@
1919
#include "php.h"
2020
#include "md5.h"
2121

22-
PHPAPI void make_digest(char *md5str, const unsigned char *digest) /* {{{ */
22+
PHPAPI void make_digest(char *md5str, const unsigned char *digest)
2323
{
2424
make_digest_ex(md5str, digest, 16);
2525
}
26-
/* }}} */
2726

28-
PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, int len) /* {{{ */
27+
PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, size_t len)
2928
{
3029
static const char hexits[17] = "0123456789abcdef";
31-
int i;
3230

33-
for (i = 0; i < len; i++) {
31+
for (size_t i = 0; i < len; i++) {
3432
md5str[i * 2] = hexits[digest[i] >> 4];
3533
md5str[(i * 2) + 1] = hexits[digest[i] & 0x0F];
3634
}
3735
md5str[len * 2] = '\0';
3836
}
39-
/* }}} */
4037

41-
/* {{{ Calculate the md5 hash of a string */
38+
/* Calculate the md5 hash of a string */
4239
PHP_FUNCTION(md5)
4340
{
4441
zend_string *arg;
45-
bool raw_output = 0;
4642
PHP_MD5_CTX context;
4743
unsigned char digest[16];
44+
bool raw_output = false;
4845

4946
ZEND_PARSE_PARAMETERS_START(1, 2)
5047
Z_PARAM_STR(arg)
@@ -63,14 +60,13 @@ PHP_FUNCTION(md5)
6360
}
6461

6562
}
66-
/* }}} */
6763

68-
/* {{{ Calculate the md5 hash of given filename */
64+
/* Calculate the md5 hash of given filename */
6965
PHP_FUNCTION(md5_file)
7066
{
7167
char *arg;
7268
size_t arg_len;
73-
bool raw_output = 0;
69+
bool raw_output = false;
7470
unsigned char buf[1024];
7571
unsigned char digest[16];
7672
PHP_MD5_CTX context;
@@ -113,7 +109,6 @@ PHP_FUNCTION(md5_file)
113109
make_digest_ex(Z_STRVAL_P(return_value), digest, 16);
114110
}
115111
}
116-
/* }}} */
117112

118113
/*
119114
* This is an OpenSSL-compatible implementation of the RSA Data Security,

ext/standard/md5.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define MD5_H
2020

2121
PHPAPI void make_digest(char *md5str, const unsigned char *digest);
22-
PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, int len);
22+
PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, size_t len);
2323

2424
/*
2525
* This is an OpenSSL-compatible implementation of the RSA Data Security,

0 commit comments

Comments
 (0)