mem: fix overflow on allocation