commit - 4a6cd10658be56430c4801ea6189fdbf2faf222d
commit + 136edb7cbf62a4878345a8f4819240a09679d5f3
blob - 07004141c4ea65df9faf9ac86dfc2e6223d65afd
blob + c6325722b033869d39e2520efd13b0c98ddada3e
--- pdf.c
+++ pdf.c
{
const HParsedToken *x = p->ast;
int64_t sgn = 1;
- uint64_t toolarge = -(INT64_MIN+1); // XXX bypass not being able to negate INT64_MIN due to two's complement
- toolarge += 1;
+ uint64_t abs_INT64_MIN = ((uint64_t) -(INT64_MIN + 1)) + 1;
+ /* equals -INT64_MIN but avoids an overflow warning */
if (x->token_type == TT_SEQUENCE) {
sgn = H_FIELD_SINT(0);
assert(sgn == 1 || sgn == -1);
switch (x->token_type) {
case TT_UINT:
- if (x->uint > toolarge) /* would overflow */
+ if ((sgn > 0 && x->uint > INT64_MAX) ||
+ (sgn < 0 && x->uint > abs_INT64_MIN))
return NULL; // XXX structured error type
return H_MAKE_SINT(sgn * x->uint);
case TT_DOUBLE: