Skip to content

Commit

Permalink
Merge pull request #4716 from WalterBright/sorting-overflow
Browse files Browse the repository at this point in the history
sorting.d: add overflow checks
  • Loading branch information
schveiguy committed Aug 5, 2016
2 parents 589a00a + ec8534d commit c4578cd
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 c4578cd

Please sign in to comment.