From 596fbf7393777cb14006813111875db5b0a21d3b Mon Sep 17 00:00:00 2001 From: Kalle Sommer Nielsen Date: Wed, 3 Oct 2018 08:48:27 +0200 Subject: [PATCH] Fix compiler warnings in ext/hash --- ext/hash/hash.c | 30 +++++++++++++++--------------- ext/hash/hash_gost.c | 4 ++-- ext/hash/hash_md.c | 2 +- ext/hash/hash_snefru.c | 4 ++-- ext/hash/hash_tiger.c | 4 ++-- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ext/hash/hash.c b/ext/hash/hash.c index 2f4bf013db..a6d881b7b4 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -151,11 +151,11 @@ static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_ size_t n; while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) { - ops->hash_update(context, (unsigned char *) buf, n); + ops->hash_update(context, (unsigned char *) buf, (unsigned int) n); } php_stream_close(stream); } else { - ops->hash_update(context, (unsigned char *) data, data_len); + ops->hash_update(context, (unsigned char *) data, (unsigned int) data_len); } digest = zend_string_alloc(ops->digest_size, 0); @@ -213,7 +213,7 @@ static inline void php_hash_hmac_prep_key(unsigned char *K, const php_hash_ops * if (key_len > (size_t)ops->block_size) { /* Reduce the key first */ ops->hash_init(context); - ops->hash_update(context, key, key_len); + ops->hash_update(context, key, (unsigned int) key_len); ops->hash_final(K, context); } else { memcpy(K, key, key_len); @@ -225,7 +225,7 @@ static inline void php_hash_hmac_prep_key(unsigned char *K, const php_hash_ops * static inline void php_hash_hmac_round(unsigned char *final, const php_hash_ops *ops, void *context, const unsigned char *key, const unsigned char *data, const zend_long data_size) { ops->hash_init(context); ops->hash_update(context, key, ops->block_size); - ops->hash_update(context, data, data_size); + ops->hash_update(context, data, (unsigned int) data_size); ops->hash_final(final, context); } @@ -276,11 +276,11 @@ static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename, if (isfilename) { char buf[1024]; - int n; + size_t n; ops->hash_init(context); ops->hash_update(context, K, ops->block_size); while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) { - ops->hash_update(context, (unsigned char *) buf, n); + ops->hash_update(context, (unsigned char *) buf, (unsigned int) n); } php_stream_close(stream); ops->hash_final((unsigned char *) ZSTR_VAL(digest), context); @@ -379,7 +379,7 @@ static void php_hashcontext_ctor(INTERNAL_FUNCTION_PARAMETERS, zval *objval) { if (ZSTR_LEN(key) > (size_t)ops->block_size) { /* Reduce the key first */ - ops->hash_update(context, (unsigned char *) ZSTR_VAL(key), ZSTR_LEN(key)); + ops->hash_update(context, (unsigned char *) ZSTR_VAL(key), (unsigned int) ZSTR_LEN(key)); ops->hash_final((unsigned char *) K, context); /* Make the context ready to start over */ ops->hash_init(context); @@ -427,7 +427,7 @@ PHP_FUNCTION(hash_update) hash = php_hashcontext_from_object(Z_OBJ_P(zhash)); PHP_HASHCONTEXT_VERIFY("hash_update", hash); - hash->ops->hash_update(hash->context, (unsigned char *) ZSTR_VAL(data), ZSTR_LEN(data)); + hash->ops->hash_update(hash->context, (unsigned char *) ZSTR_VAL(data), (unsigned int) ZSTR_LEN(data)); RETURN_TRUE; } @@ -462,7 +462,7 @@ PHP_FUNCTION(hash_update_stream) /* Nada mas */ RETURN_LONG(didread); } - hash->ops->hash_update(hash->context, (unsigned char *) buf, n); + hash->ops->hash_update(hash->context, (unsigned char *) buf, (unsigned int) n); length -= n; didread += n; } @@ -498,7 +498,7 @@ PHP_FUNCTION(hash_update_file) } while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) { - hash->ops->hash_update(hash->context, (unsigned char *) buf, n); + hash->ops->hash_update(hash->context, (unsigned char *) buf, (unsigned int) n); } php_stream_close(stream); @@ -671,7 +671,7 @@ PHP_FUNCTION(hash_hkdf) // Expand returnval = zend_string_alloc(length, 0); digest = emalloc(ops->digest_size); - for (i = 1, rounds = (length - 1) / ops->digest_size + 1; i <= rounds; i++) { + for (i = 1, rounds = (int)(length - 1) / ops->digest_size + 1; i <= rounds; i++) { // chr(i) unsigned char c[1]; c[0] = (i & 0xFF); @@ -685,7 +685,7 @@ PHP_FUNCTION(hash_hkdf) } if (info != NULL && ZSTR_LEN(info) > 0) { - ops->hash_update(context, (unsigned char *) ZSTR_VAL(info), ZSTR_LEN(info)); + ops->hash_update(context, (unsigned char *) ZSTR_VAL(info), (unsigned int) ZSTR_LEN(info)); } ops->hash_update(context, c, 1); @@ -831,7 +831,7 @@ PHP_FUNCTION(hash_pbkdf2) if (raw_output) { memcpy(ZSTR_VAL(returnval), result, length); } else { - php_hash_bin2hex(ZSTR_VAL(returnval), result, digest_length); + php_hash_bin2hex(ZSTR_VAL(returnval), result, (unsigned int) digest_length); } ZSTR_VAL(returnval)[length] = 0; efree(result); @@ -1083,8 +1083,8 @@ PHP_FUNCTION(mhash_keygen_s2k) for (j=0;jhash_update(context, &null, 1); } - ops->hash_update(context, (unsigned char *)padded_salt, salt_len); - ops->hash_update(context, (unsigned char *)password, password_len); + ops->hash_update(context, (unsigned char *)padded_salt, (unsigned int) salt_len); + ops->hash_update(context, (unsigned char *)password, (unsigned int) password_len); ops->hash_final((unsigned char *)digest, context); memcpy( &key[i*block_size], digest, block_size); } diff --git a/ext/hash/hash_gost.c b/ext/hash/hash_gost.c index e18de57d9d..352f7364bb 100644 --- a/ext/hash/hash_gost.c +++ b/ext/hash/hash_gost.c @@ -256,9 +256,9 @@ PHP_HASH_API void PHP_GOSTUpdate(PHP_GOST_CTX *context, const unsigned char *inp if ((MAX32 - context->count[0]) < (len * 8)) { context->count[1]++; context->count[0] = MAX32 - context->count[0]; - context->count[0] = (len * 8) - context->count[0]; + context->count[0] = (uint32_t)(len * 8) - context->count[0]; } else { - context->count[0] += len * 8; + context->count[0] += (uint32_t) (len * 8); } if (context->length + len < 32) { diff --git a/ext/hash/hash_md.c b/ext/hash/hash_md.c index 3cbd00a215..be66f6a9cd 100644 --- a/ext/hash/hash_md.c +++ b/ext/hash/hash_md.c @@ -679,7 +679,7 @@ PHP_HASH_API void PHP_MD2Update(PHP_MD2_CTX *context, const unsigned char *buf, /* Copy remaining data to buffer */ if (p < e) { memcpy(context->buffer, p, e - p); - context->in_buffer = e - p; + context->in_buffer = (char)(e - p); } } diff --git a/ext/hash/hash_snefru.c b/ext/hash/hash_snefru.c index bab15c505a..e8628ad7fa 100644 --- a/ext/hash/hash_snefru.c +++ b/ext/hash/hash_snefru.c @@ -142,9 +142,9 @@ PHP_HASH_API void PHP_SNEFRUUpdate(PHP_SNEFRU_CTX *context, const unsigned char if ((MAX32 - context->count[1]) < (len * 8)) { context->count[0]++; context->count[1] = MAX32 - context->count[1]; - context->count[1] = (len * 8) - context->count[1]; + context->count[1] = (uint32_t) (len * 8) - context->count[1]; } else { - context->count[1] += len * 8; + context->count[1] += (uint32_t) (len * 8); } if (context->length + len < 32) { diff --git a/ext/hash/hash_tiger.c b/ext/hash/hash_tiger.c index 720045f821..0a2acbcd6d 100644 --- a/ext/hash/hash_tiger.c +++ b/ext/hash/hash_tiger.c @@ -197,7 +197,7 @@ PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, const unsigned char *i { if (context->length + len < 64) { memcpy(&context->buffer[context->length], input, len); - context->length += len; + context->length += (unsigned int) len; } else { size_t i = 0, r = (context->length + len) % 64; @@ -216,7 +216,7 @@ PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, const unsigned char *i } ZEND_SECURE_ZERO(&context->buffer[r], 64-r); memcpy(context->buffer, &input[i], r); - context->length = r; + context->length = (unsigned int) r; } } -- 2.40.0