// SkSafeMath always check that a series of operations do not overflow. // This must be correct for all platforms, because this is a check for safety at runtime.
class SkSafeMath { public:
SkSafeMath() = default;
size_t add(size_t x, size_t y) {
size_t result = x + y;
fOK &= result >= x; return result;
}
/** * Return a + b, unless this result is an overflow/underflow. In those cases, fOK will * be set to false, and it is undefined what this returns.
*/ int addInt(int a, int b) { if (b < 0 && a < std::numeric_limits<int>::min() - b) {
fOK = false; return a;
} elseif (b > 0 && a > std::numeric_limits<int>::max() - b) {
fOK = false; return a;
} return a + b;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.