diff options
Diffstat (limited to 'include/qpdf/QIntC.hh')
-rw-r--r-- | include/qpdf/QIntC.hh | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/include/qpdf/QIntC.hh b/include/qpdf/QIntC.hh index 6f1f4b63..5f7f21bb 100644 --- a/include/qpdf/QIntC.hh +++ b/include/qpdf/QIntC.hh @@ -222,6 +222,20 @@ namespace QIntC // QIntC = qpdf Integer Conversion { return IntConverter<T, unsigned long long>::convert(i); } + + template <typename T> + void range_check(T const& cur, T const& delta) + { + if ((delta > 0) && + ((std::numeric_limits<T>::max() - cur) < delta)) + { + std::ostringstream msg; + msg.imbue(std::locale::classic()); + msg << "adding " << delta << " to " << cur + << " would cause an integer overflow"; + throw std::range_error(msg.str()); + } + } }; #endif // QINTC_HH |