Index: base/md5.cc |
diff --git a/base/md5.cc b/base/md5.cc |
index 9709a86fcd166194d0a9547f6899b55140b70ebc..72c774d35546ae0fa4c5798174a95861d5460eaf 100644 |
--- a/base/md5.cc |
+++ b/base/md5.cc |
@@ -37,11 +37,12 @@ struct Context { |
* Note: this code is harmless on little-endian machines. |
*/ |
void byteReverse(uint8_t* buf, unsigned longs) { |
- uint32_t t; |
do { |
- t = (uint32_t)((unsigned)buf[3] << 8 | buf[2]) << 16 | |
- ((unsigned)buf[1] << 8 | buf[0]); |
- *(uint32_t*)buf = t; |
+ uint32_t temp = static_cast<uint32_t>( |
+ static_cast<unsigned>(buf[3]) << 8 | |
+ buf[2]) << 16 | |
+ (static_cast<unsigned>(buf[1]) << 8 | buf[0]); |
+ *reinterpret_cast<uint32_t*>(buf) = temp; |
buf += 4; |
} while (--longs); |
} |
@@ -154,7 +155,7 @@ namespace base { |
* initialization constants. |
*/ |
void MD5Init(MD5Context* context) { |
- struct Context* ctx = (struct Context*)context; |
+ struct Context* ctx = reinterpret_cast<struct Context*>(context); |
ctx->buf[0] = 0x67452301; |
ctx->buf[1] = 0xefcdab89; |
ctx->buf[2] = 0x98badcfe; |
@@ -168,14 +169,14 @@ void MD5Init(MD5Context* context) { |
* of bytes. |
*/ |
void MD5Update(MD5Context* context, const StringPiece& data) { |
- struct Context* ctx = (struct Context*)context; |
- const uint8_t* buf = (const uint8_t*)data.data(); |
+ struct Context* ctx = reinterpret_cast<struct Context*>(context); |
+ const uint8_t* buf = reinterpret_cast<const uint8_t*>(data.data()); |
size_t len = data.size(); |
/* Update bitcount */ |
uint32_t t = ctx->bits[0]; |
- if ((ctx->bits[0] = t + ((uint32_t)len << 3)) < t) |
+ if ((ctx->bits[0] = t + (static_cast<uint32_t>(len) << 3)) < t) |
ctx->bits[1]++; /* Carry from low to high */ |
ctx->bits[1] += static_cast<uint32_t>(len >> 29); |
@@ -184,7 +185,7 @@ void MD5Update(MD5Context* context, const StringPiece& data) { |
/* Handle any leading odd-sized chunks */ |
if (t) { |
- uint8_t* p = (uint8_t*)ctx->in + t; |
+ uint8_t* p = static_cast<uint8_t*>(ctx->in + t); |
t = 64 - t; |
if (len < t) { |
@@ -193,7 +194,7 @@ void MD5Update(MD5Context* context, const StringPiece& data) { |
} |
memcpy(p, buf, t); |
byteReverse(ctx->in, 16); |
- MD5Transform(ctx->buf, (uint32_t*)ctx->in); |
+ MD5Transform(ctx->buf, reinterpret_cast<uint32_t*>(ctx->in)); |
buf += t; |
len -= t; |
} |
@@ -203,7 +204,7 @@ void MD5Update(MD5Context* context, const StringPiece& data) { |
while (len >= 64) { |
memcpy(ctx->in, buf, 64); |
byteReverse(ctx->in, 16); |
- MD5Transform(ctx->buf, (uint32_t*)ctx->in); |
+ MD5Transform(ctx->buf, reinterpret_cast<uint32_t*>(ctx->in)); |
buf += 64; |
len -= 64; |
} |
@@ -218,7 +219,7 @@ void MD5Update(MD5Context* context, const StringPiece& data) { |
* 1 0* (64-bit count of bits processed, MSB-first) |
*/ |
void MD5Final(MD5Digest* digest, MD5Context* context) { |
- struct Context* ctx = (struct Context*)context; |
+ struct Context* ctx = reinterpret_cast<struct Context*>(context); |
unsigned count; |
uint8_t* p; |
@@ -238,7 +239,7 @@ void MD5Final(MD5Digest* digest, MD5Context* context) { |
/* Two lots of padding: Pad the first block to 64 bytes */ |
memset(p, 0, count); |
byteReverse(ctx->in, 16); |
- MD5Transform(ctx->buf, (uint32_t*)ctx->in); |
+ MD5Transform(ctx->buf, reinterpret_cast<uint32_t*>(ctx->in)); |
/* Now fill the next block with 56 bytes */ |
memset(ctx->in, 0, 56); |
@@ -254,8 +255,8 @@ void MD5Final(MD5Digest* digest, MD5Context* context) { |
memcpy(&ctx->in[15 * sizeof(ctx->bits[1])], &ctx->bits[1], |
sizeof(ctx->bits[1])); |
- MD5Transform(ctx->buf, (uint32_t*)ctx->in); |
- byteReverse((uint8_t*)ctx->buf, 4); |
+ MD5Transform(ctx->buf, reinterpret_cast<uint32_t*>(ctx->in)); |
+ byteReverse(reinterpret_cast<uint8_t*>(ctx->buf), 4); |
memcpy(digest->a, ctx->buf, 16); |
memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ |
} |