Skip to content

Commit fabbd8e

Browse files
committed
Omit a redundant error check if sizeof(HashtableItem) > 10
`sizeof(HashtableItem)` should be always > 10 for all platforms htop currently supports (32-bit or 64-bit). If `Hashtable.size > SIZE_MAX / sizeof(HashtableItem)`, the buffer allocation would fail at xCalloc(), and a conditional for checking `size` overflow would be redundant. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
1 parent 34f822b commit fabbd8e

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

Hashtable.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,12 @@ void Hashtable_put(Hashtable* this, ht_key_t key, void* value) {
224224

225225
assert(Hashtable_isConsistent(this));
226226
assert(this->size > 0);
227+
assert(this->size <= SIZE_MAX / sizeof(HashtableItem));
227228
assert(value);
228229

229230
/* grow on load-factor > 0.7 */
230231
if (10 * this->items > 7 * this->size) {
231-
if (SIZE_MAX / 2 < this->size)
232+
if (sizeof(HashtableItem) < 10 && SIZE_MAX / 10 < this->size)
232233
CRT_fatalError("Hashtable: size overflow");
233234

234235
Hashtable_setSize(this, 2 * this->size);

0 commit comments

Comments
 (0)