mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 15:10:46 +03:00
sorting.d: add overflow checks
This commit is contained in:
parent
ee30556a34
commit
ec8534d58b
1 changed files with 5 additions and 1 deletions
|
@ -2179,7 +2179,11 @@ schwartzSort(alias transform, alias less = "a < b",
|
|||
static trustedMalloc(size_t len) @trusted
|
||||
{
|
||||
import core.stdc.stdlib : malloc;
|
||||
return (cast(T*) malloc(len * T.sizeof))[0 .. len];
|
||||
import core.checkedint : mulu;
|
||||
bool overflow;
|
||||
const nbytes = mulu(len, T.sizeof, overflow);
|
||||
if (overflow) assert(0);
|
||||
return (cast(T*) malloc(nbytes))[0 .. len];
|
||||
}
|
||||
auto xform1 = trustedMalloc(r.length);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue