Skip to content

Commit

Permalink
sorting.d: add overflow checks
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Aug 5, 2016
1 parent ee30556 commit ec8534d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion std/algorithm/sorting.d
Expand Up @@ -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);

Expand Down

0 comments on commit ec8534d

Please sign in to comment.