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>
chromium-stable
David Benjamin 1 year ago committed by Boringssl LUCI CQ
parent 216db679a7
commit 8d0a83da9a
  1. 2
      crypto/evp/scrypt.c
  2. 2
      crypto/fipsmodule/bn/ctx.c
  3. 2
      crypto/fipsmodule/bn/exponentiation.c
  4. 2
      crypto/fipsmodule/cipher/e_aesccm.c
  5. 2
      crypto/fipsmodule/dh/dh.c

@ -170,7 +170,7 @@ int EVP_PBE_scrypt(const char *password, size_t password_len,
// 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;

@ -210,7 +210,7 @@ static int BN_STACK_push(BN_STACK *st, size_t idx) {
// 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 =

@ -724,7 +724,7 @@ void bn_mod_exp_mont_small(BN_ULONG *r, const BN_ULONG *a, size_t num,
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));

@ -86,7 +86,7 @@ static int CRYPTO_ccm128_init(struct ccm128_context *ctx, const AES_KEY *key,
}
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;
}

@ -394,7 +394,7 @@ int DH_compute_key(unsigned char *out, const BIGNUM *peers_key, DH *dh) {
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) {

Loading…
Cancel
Save