Skip to content

Commit cc8bdee

Browse files
committed
Fix allocation non-overflow precondition
1 parent 48b1942 commit cc8bdee

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/hash.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ static R_INLINE size_t get_full_size(size_t n_elements, double load_factor) {
4040

4141
static hashtab * hash_create_(size_t n, double load_factor) {
4242
size_t n_full = get_full_size(n, load_factor);
43-
// precondition: sizeof hashtab + hash_pair[n_full] < SIZE_MAX
44-
// n_full * sizeof hash_pair < SIZE_MAX - sizeof hashtab
45-
// sizeof hash_pair < (SIZE_MAX - sizeof hashtab) / n_full
43+
// precondition: sizeof hash_pair[n_full] < SIZE_MAX
4644
// (note that sometimes n is 0)
47-
if (n_full && sizeof(struct hash_pair) >= (SIZE_MAX - sizeof(hashtab)) / n_full)
45+
if (n_full && sizeof(struct hash_pair) >= SIZE_MAX / n_full)
4846
internal_error(
4947
__func__, "n=%zu with load_factor=%g would overflow total allocation size",
5048
n, load_factor

0 commit comments

Comments
 (0)