Skip to content

Commit 1ae1768

Browse files
committed
vcomp/cmpto_j2k: check val dst type upper bound
check maximal value to fit the destination target type Note: the `nextafter(..., -INF)` is used to represent a value of type max that is also representable by double. Depending on the rounding mode, eg. `(double) LLONG_MAX` may round up - in this case 9223372036854775807 becomes ..808. improves <#473>
1 parent 1735e6a commit 1ae1768

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/video_compress/cmpto_j2k.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
#endif // HAVE_CONFIG_H
5353

5454
#include <cassert>
55-
#include <cfloat>
5655
#include <cmath>
57-
#include <climits>
5856
#include <condition_variable>
57+
#include <cstdint> // for uintmax_t
58+
#include <limits> // for numeric_limits
5959
#include <mutex>
6060
#include <string>
6161
#include <utility>
@@ -737,7 +737,10 @@ static void usage(bool full) {
737737
if (std::isnan(val)) { \
738738
return nullptr; \
739739
} \
740-
if (val < (minval) || val > DBL_MAX) { \
740+
const uintmax_t maxval = \
741+
std::nextafter(std::numeric_limits<typeof(var)>::max(), \
742+
-std::numeric_limits<double>::infinity()); \
743+
if (val < (minval) || val > maxval) { \
741744
LOG(LOG_LEVEL_ERROR) \
742745
<< "[J2K] Wrong value " << (str) \
743746
<< " for " #var "! Value must be >= " << (minval) \

0 commit comments

Comments
 (0)