Skip to content

Commit 596fbf7

Browse files
committed
Fix compiler warnings in ext/hash
1 parent f73c010 commit 596fbf7

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

ext/hash/hash.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_
151151
size_t n;
152152

153153
while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
154-
ops->hash_update(context, (unsigned char *) buf, n);
154+
ops->hash_update(context, (unsigned char *) buf, (unsigned int) n);
155155
}
156156
php_stream_close(stream);
157157
} else {
158-
ops->hash_update(context, (unsigned char *) data, data_len);
158+
ops->hash_update(context, (unsigned char *) data, (unsigned int) data_len);
159159
}
160160

161161
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 *
213213
if (key_len > (size_t)ops->block_size) {
214214
/* Reduce the key first */
215215
ops->hash_init(context);
216-
ops->hash_update(context, key, key_len);
216+
ops->hash_update(context, key, (unsigned int) key_len);
217217
ops->hash_final(K, context);
218218
} else {
219219
memcpy(K, key, key_len);
@@ -225,7 +225,7 @@ static inline void php_hash_hmac_prep_key(unsigned char *K, const php_hash_ops *
225225
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) {
226226
ops->hash_init(context);
227227
ops->hash_update(context, key, ops->block_size);
228-
ops->hash_update(context, data, data_size);
228+
ops->hash_update(context, data, (unsigned int) data_size);
229229
ops->hash_final(final, context);
230230
}
231231

@@ -276,11 +276,11 @@ static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename,
276276

277277
if (isfilename) {
278278
char buf[1024];
279-
int n;
279+
size_t n;
280280
ops->hash_init(context);
281281
ops->hash_update(context, K, ops->block_size);
282282
while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
283-
ops->hash_update(context, (unsigned char *) buf, n);
283+
ops->hash_update(context, (unsigned char *) buf, (unsigned int) n);
284284
}
285285
php_stream_close(stream);
286286
ops->hash_final((unsigned char *) ZSTR_VAL(digest), context);
@@ -379,7 +379,7 @@ static void php_hashcontext_ctor(INTERNAL_FUNCTION_PARAMETERS, zval *objval) {
379379

380380
if (ZSTR_LEN(key) > (size_t)ops->block_size) {
381381
/* Reduce the key first */
382-
ops->hash_update(context, (unsigned char *) ZSTR_VAL(key), ZSTR_LEN(key));
382+
ops->hash_update(context, (unsigned char *) ZSTR_VAL(key), (unsigned int) ZSTR_LEN(key));
383383
ops->hash_final((unsigned char *) K, context);
384384
/* Make the context ready to start over */
385385
ops->hash_init(context);
@@ -427,7 +427,7 @@ PHP_FUNCTION(hash_update)
427427

428428
hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
429429
PHP_HASHCONTEXT_VERIFY("hash_update", hash);
430-
hash->ops->hash_update(hash->context, (unsigned char *) ZSTR_VAL(data), ZSTR_LEN(data));
430+
hash->ops->hash_update(hash->context, (unsigned char *) ZSTR_VAL(data), (unsigned int) ZSTR_LEN(data));
431431

432432
RETURN_TRUE;
433433
}
@@ -462,7 +462,7 @@ PHP_FUNCTION(hash_update_stream)
462462
/* Nada mas */
463463
RETURN_LONG(didread);
464464
}
465-
hash->ops->hash_update(hash->context, (unsigned char *) buf, n);
465+
hash->ops->hash_update(hash->context, (unsigned char *) buf, (unsigned int) n);
466466
length -= n;
467467
didread += n;
468468
}
@@ -498,7 +498,7 @@ PHP_FUNCTION(hash_update_file)
498498
}
499499

500500
while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
501-
hash->ops->hash_update(hash->context, (unsigned char *) buf, n);
501+
hash->ops->hash_update(hash->context, (unsigned char *) buf, (unsigned int) n);
502502
}
503503
php_stream_close(stream);
504504

@@ -671,7 +671,7 @@ PHP_FUNCTION(hash_hkdf)
671671
// Expand
672672
returnval = zend_string_alloc(length, 0);
673673
digest = emalloc(ops->digest_size);
674-
for (i = 1, rounds = (length - 1) / ops->digest_size + 1; i <= rounds; i++) {
674+
for (i = 1, rounds = (int)(length - 1) / ops->digest_size + 1; i <= rounds; i++) {
675675
// chr(i)
676676
unsigned char c[1];
677677
c[0] = (i & 0xFF);
@@ -685,7 +685,7 @@ PHP_FUNCTION(hash_hkdf)
685685
}
686686

687687
if (info != NULL && ZSTR_LEN(info) > 0) {
688-
ops->hash_update(context, (unsigned char *) ZSTR_VAL(info), ZSTR_LEN(info));
688+
ops->hash_update(context, (unsigned char *) ZSTR_VAL(info), (unsigned int) ZSTR_LEN(info));
689689
}
690690

691691
ops->hash_update(context, c, 1);
@@ -831,7 +831,7 @@ PHP_FUNCTION(hash_pbkdf2)
831831
if (raw_output) {
832832
memcpy(ZSTR_VAL(returnval), result, length);
833833
} else {
834-
php_hash_bin2hex(ZSTR_VAL(returnval), result, digest_length);
834+
php_hash_bin2hex(ZSTR_VAL(returnval), result, (unsigned int) digest_length);
835835
}
836836
ZSTR_VAL(returnval)[length] = 0;
837837
efree(result);
@@ -1083,8 +1083,8 @@ PHP_FUNCTION(mhash_keygen_s2k)
10831083
for (j=0;j<i;j++) {
10841084
ops->hash_update(context, &null, 1);
10851085
}
1086-
ops->hash_update(context, (unsigned char *)padded_salt, salt_len);
1087-
ops->hash_update(context, (unsigned char *)password, password_len);
1086+
ops->hash_update(context, (unsigned char *)padded_salt, (unsigned int) salt_len);
1087+
ops->hash_update(context, (unsigned char *)password, (unsigned int) password_len);
10881088
ops->hash_final((unsigned char *)digest, context);
10891089
memcpy( &key[i*block_size], digest, block_size);
10901090
}

ext/hash/hash_gost.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ PHP_HASH_API void PHP_GOSTUpdate(PHP_GOST_CTX *context, const unsigned char *inp
256256
if ((MAX32 - context->count[0]) < (len * 8)) {
257257
context->count[1]++;
258258
context->count[0] = MAX32 - context->count[0];
259-
context->count[0] = (len * 8) - context->count[0];
259+
context->count[0] = (uint32_t)(len * 8) - context->count[0];
260260
} else {
261-
context->count[0] += len * 8;
261+
context->count[0] += (uint32_t) (len * 8);
262262
}
263263

264264
if (context->length + len < 32) {

ext/hash/hash_md.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ PHP_HASH_API void PHP_MD2Update(PHP_MD2_CTX *context, const unsigned char *buf,
679679
/* Copy remaining data to buffer */
680680
if (p < e) {
681681
memcpy(context->buffer, p, e - p);
682-
context->in_buffer = e - p;
682+
context->in_buffer = (char)(e - p);
683683
}
684684
}
685685

ext/hash/hash_snefru.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ PHP_HASH_API void PHP_SNEFRUUpdate(PHP_SNEFRU_CTX *context, const unsigned char
142142
if ((MAX32 - context->count[1]) < (len * 8)) {
143143
context->count[0]++;
144144
context->count[1] = MAX32 - context->count[1];
145-
context->count[1] = (len * 8) - context->count[1];
145+
context->count[1] = (uint32_t) (len * 8) - context->count[1];
146146
} else {
147-
context->count[1] += len * 8;
147+
context->count[1] += (uint32_t) (len * 8);
148148
}
149149

150150
if (context->length + len < 32) {

ext/hash/hash_tiger.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, const unsigned char *i
197197
{
198198
if (context->length + len < 64) {
199199
memcpy(&context->buffer[context->length], input, len);
200-
context->length += len;
200+
context->length += (unsigned int) len;
201201
} else {
202202
size_t i = 0, r = (context->length + len) % 64;
203203

@@ -216,7 +216,7 @@ PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, const unsigned char *i
216216
}
217217
ZEND_SECURE_ZERO(&context->buffer[r], 64-r);
218218
memcpy(context->buffer, &input[i], r);
219-
context->length = r;
219+
context->length = (unsigned int) r;
220220
}
221221
}
222222

0 commit comments

Comments
 (0)