Skip to content

Commit b7894e6

Browse files
committed
Leave overflow checking to R_alloc
1 parent 99ede05 commit b7894e6

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

src/hash.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,13 @@ 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 hash_pair[n_full] < SIZE_MAX
44-
// (note that sometimes n is 0)
45-
if (n_full && sizeof(struct hash_pair) >= SIZE_MAX / n_full)
46-
internal_error(
47-
__func__, "n=%zu with load_factor=%g would overflow total allocation size",
48-
n, load_factor
49-
);
5043
hashtab *ret = (hashtab *)R_alloc(sizeof(hashtab), 1);
5144
ret->size = n_full;
5245
ret->free = n;
5346
// Multiply by size to get different hash functions when rehashing
5447
ret->multiplier1 = n_full * hash_multiplier1;
5548
ret->multiplier2 = n_full * hash_multiplier2;
56-
ret->table = (struct hash_pair *)R_alloc(sizeof(struct hash_pair[n_full]), 1);
49+
ret->table = (struct hash_pair *)R_alloc(n_full, sizeof(*ret->table));
5750
// No valid SEXP is a null pointer, so it's a safe marker for empty cells.
5851
for (size_t i = 0; i < n_full; ++i) {
5952
ret->table[i].key = NULL;

0 commit comments

Comments
 (0)