sorting.d: add overflow checks

This commit is contained in:
Walter Bright 2016-08-05 00:44:20 -07:00
parent ee30556a34
commit ec8534d58b

View file

@ -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);