From 3608afd5c528b7a9d95d227cb6c4f33d303fcfcd Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 20 Jun 2019 13:04:57 -0400 Subject: Add new integer accessors to QPDFObjectHandle --- libqpdf/QPDFObjectHandle.cc | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'libqpdf') diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 2cffb166..b3f7daec 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -26,6 +26,7 @@ #include #include #include +#include class TerminateParsing { @@ -406,6 +407,82 @@ QPDFObjectHandle::getIntValue() } } +int +QPDFObjectHandle::getIntValueAsInt() +{ + int result = 0; + long long v = getIntValue(); + if (v < INT_MIN) + { + QTC::TC("qpdf", "QPDFObjectHandle int returning INT_MIN"); + warnIfPossible( + "requested value of integer is too small; returning INT_MIN", + false); + result = INT_MIN; + } + else if (v > INT_MAX) + { + QTC::TC("qpdf", "QPDFObjectHandle int returning INT_MAX"); + warnIfPossible( + "requested value of integer is too big; returning INT_MAX", + false); + result = INT_MAX; + } + else + { + result = static_cast(v); + } + return result; +} + +unsigned long long +QPDFObjectHandle::getUIntValue() +{ + unsigned long long result = 0; + long long v = getIntValue(); + if (v < 0) + { + QTC::TC("qpdf", "QPDFObjectHandle uint returning 0"); + warnIfPossible( + "unsigned value request for negative number; returning 0", + false); + } + else + { + result = static_cast(v); + } + return result; +} + +unsigned int +QPDFObjectHandle::getUIntValueAsUInt() +{ + unsigned int result = 0; + long long v = getIntValue(); + if (v < 0) + { + QTC::TC("qpdf", "QPDFObjectHandle uint uint returning 0"); + warnIfPossible( + "unsigned integer value request for negative number; returning 0", + false); + result = 0; + } + else if (v > UINT_MAX) + { + QTC::TC("qpdf", "QPDFObjectHandle uint returning UINT_MAX"); + warnIfPossible( + "requested value of unsigned integer is too big;" + " returning UINT_MAX", + false); + result = UINT_MAX; + } + else + { + result = static_cast(v); + } + return result; +} + // Real accessors std::string -- cgit v1.2.3-54-g00ecf