Fix signed integer overflow UB in complexity computations.

Previously the FittingCurve functions for n^2 and n^3 did the calculation
using int types. This can overflow and cause UB. This patch changes the
calculations to use std::pow to prevent this.

Also re-enable VC 2013 appveyor bot since I *hope* this is what was causing
the failures.
This commit is contained in:
Eric Fiselier 2016-08-07 17:33:18 -06:00
parent 5121b8546b
commit c04f703ab4
2 changed files with 3 additions and 3 deletions

View File

@ -12,7 +12,7 @@ platform:
environment:
matrix:
# - compiler: msvc-12-seh
- compiler: msvc-12-seh
- compiler: msvc-14-seh
- compiler: gcc-4.9.2-posix
# - compiler: gcc-4.8.4-posix

View File

@ -31,9 +31,9 @@ BigOFunc* FittingCurve(BigO complexity) {
case oN:
return [](int n) -> double { return n; };
case oNSquared:
return [](int n) -> double { return n * n; };
return [](int n) -> double { return std::pow(n, 2); };
case oNCubed:
return [](int n) -> double { return n * n * n; };
return [](int n) -> double { return std::pow(n, 3); };
case oLogN:
return [](int n) { return std::log2(n); };
case oNLogN: