[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

**To**:**tech-userlevel%netbsd.org@localhost****Subject**:**Questioning the overflow check in jemalloc****From**:**Pierre Pronchery <khorben%defora.org@localhost>**- Date: Thu, 7 Sep 2017 15:56:15 +0200

Hi tech-userlevel@,

3857 /* 3858 * Try to avoid division here. We know that it isn't possible to 3859 * overflow during multiplication if neither operand uses any of the 3860 * most significant half of the bits in a size_t. 3861 */ 3862 } else if ((unsigned long long)((num | size) & 3863 ((unsigned long long)SIZE_T_MAX << (sizeof(size_t) << 2))) && 3864 (num_size / size != num)) { 3865 /* size_t overflow. */ 3866 ret = NULL; 3867 goto RETURN; 3868 }

I think we essentially have two cases here: - typical 32-bit platform where sizeof(size_t) is 4, therefore sizeof(unsigned long long) > sizeof(size_t) - typical 64-bit platform where sizeof(size_t) is 8, therefore sizeof(unsigned long long) == sizeof(size_t)

References: - https://github.com/NetBSD/src/blob/trunk/lib/libc/stdlib/jemalloc.c#L3837 - BSR instruction, http://x86.renejeschke.de/html/file_module_x86_id_20.html - https://en.wikipedia.org/wiki/Find_first_set Cheers, -- khorben

**Follow-Ups**:**Re: Questioning the overflow check in jemalloc***From:*Joerg Sonnenberger

- Prev by Date:
**Re: kdump -E for time elapsed since the beginning of trace** - Next by Date:
**Re: Questioning the overflow check in jemalloc** - Previous by Thread:
**kdump -E for time elapsed since the beginning of trace** - Next by Thread:
**Re: Questioning the overflow check in jemalloc** - Indexes: