Consistently use SIZE_MAX over (size_t)-1
Change-Id: Idcf76ef4b5a023cf2a3fa71565c4aaddc921183d
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/63385
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/crypto/evp/scrypt.c b/crypto/evp/scrypt.c
index 7d35597..2830267 100644
--- a/crypto/evp/scrypt.c
+++ b/crypto/evp/scrypt.c
@@ -170,7 +170,7 @@
// Allocate and divide up the scratch space. |max_mem| fits in a size_t, which
// is no bigger than uint64_t, so none of these operations may overflow.
- static_assert(UINT64_MAX >= ((size_t)-1), "size_t exceeds uint64_t");
+ static_assert(UINT64_MAX >= SIZE_MAX, "size_t exceeds uint64_t");
size_t B_blocks = p * 2 * r;
size_t B_bytes = B_blocks * sizeof(block_t);
size_t T_blocks = 2 * r;
diff --git a/crypto/fipsmodule/bn/ctx.c b/crypto/fipsmodule/bn/ctx.c
index 0073161..740fb78 100644
--- a/crypto/fipsmodule/bn/ctx.c
+++ b/crypto/fipsmodule/bn/ctx.c
@@ -210,7 +210,7 @@
// This function intentionally does not push to the error queue on error.
// Error-reporting is deferred to |BN_CTX_get|.
size_t new_size = st->size != 0 ? st->size * 3 / 2 : BN_CTX_START_FRAMES;
- if (new_size <= st->size || new_size > ((size_t)-1) / sizeof(size_t)) {
+ if (new_size <= st->size || new_size > SIZE_MAX / sizeof(size_t)) {
return 0;
}
size_t *new_indexes =
diff --git a/crypto/fipsmodule/bn/exponentiation.c b/crypto/fipsmodule/bn/exponentiation.c
index 41c7233..632771e 100644
--- a/crypto/fipsmodule/bn/exponentiation.c
+++ b/crypto/fipsmodule/bn/exponentiation.c
@@ -724,7 +724,7 @@
const BN_ULONG *p, size_t num_p,
const BN_MONT_CTX *mont) {
if (num != (size_t)mont->N.width || num > BN_SMALL_MAX_WORDS ||
- num_p > ((size_t)-1) / BN_BITS2) {
+ num_p > SIZE_MAX / BN_BITS2) {
abort();
}
assert(BN_is_odd(&mont->N));
diff --git a/crypto/fipsmodule/cipher/e_aesccm.c b/crypto/fipsmodule/cipher/e_aesccm.c
index c00bf61..295aa05 100644
--- a/crypto/fipsmodule/cipher/e_aesccm.c
+++ b/crypto/fipsmodule/cipher/e_aesccm.c
@@ -86,7 +86,7 @@
}
static size_t CRYPTO_ccm128_max_input(const struct ccm128_context *ctx) {
- return ctx->L >= sizeof(size_t) ? (size_t)-1
+ return ctx->L >= sizeof(size_t) ? SIZE_MAX
: (((size_t)1) << (ctx->L * 8)) - 1;
}
diff --git a/crypto/fipsmodule/dh/dh.c b/crypto/fipsmodule/dh/dh.c
index d57b093..39c6b8e 100644
--- a/crypto/fipsmodule/dh/dh.c
+++ b/crypto/fipsmodule/dh/dh.c
@@ -394,7 +394,7 @@
int DH_compute_key_hashed(DH *dh, uint8_t *out, size_t *out_len,
size_t max_out_len, const BIGNUM *peers_key,
const EVP_MD *digest) {
- *out_len = (size_t)-1;
+ *out_len = SIZE_MAX;
const size_t digest_len = EVP_MD_size(digest);
if (digest_len > max_out_len) {