From b5e3a7aef2b38d09069a7ac0f7887f295d28a2a8 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 11 Nov 2016 10:59:42 -0700 Subject: [PATCH] Cast len from size_t to uint64_t before bit shifting since we are adding to count which is also uint64_t. Quiets a PVS-Studio warning. --- lib/util/sha2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/util/sha2.c b/lib/util/sha2.c index b04abd91f..225a02640 100644 --- a/lib/util/sha2.c +++ b/lib/util/sha2.c @@ -255,7 +255,7 @@ SHA256Update(SHA2_CTX *ctx, const uint8_t *data, size_t len) size_t i = 0, j; j = (size_t)((ctx->count[0] >> 3) & (SHA256_BLOCK_LENGTH - 1)); - ctx->count[0] += (len << 3); + ctx->count[0] += ((uint64_t)len << 3); if ((j + len) > SHA256_BLOCK_LENGTH - 1) { memcpy(&ctx->buffer[j], data, (i = SHA256_BLOCK_LENGTH - j)); SHA256Transform(ctx->state.st32, ctx->buffer); @@ -466,8 +466,8 @@ SHA512Update(SHA2_CTX *ctx, const uint8_t *data, size_t len) size_t i = 0, j; j = (size_t)((ctx->count[0] >> 3) & (SHA512_BLOCK_LENGTH - 1)); - ctx->count[0] += (len << 3); - if (ctx->count[0] < (len << 3)) + ctx->count[0] += ((uint64_t)len << 3); + if (ctx->count[0] < ((uint64_t)len << 3)) ctx->count[1]++; if ((j + len) > SHA512_BLOCK_LENGTH - 1) { memcpy(&ctx->buffer[j], data, (i = SHA512_BLOCK_LENGTH - j)); -- 2.40.0