--- CBOR-XS/XS.xs 2016/11/26 00:47:02 1.60 +++ CBOR-XS/XS.xs 2016/11/26 02:10:19 1.61 @@ -8,6 +8,7 @@ #include #include #include +#include #define ECB_NO_THREADS 1 #include "ecb.h" @@ -188,15 +189,12 @@ ecb_inline int minimum_string_length (UV idx) { - return idx > 23 - ? idx > 0xffU - ? idx > 0xffffU - ? idx > 0xffffffffU - ? 11 - : 7 - : 5 - : 4 - : 3; + + return idx <= 23 ? 3 + : idx <= 0xffU ? 4 + : idx <= 0xffffU ? 5 + : idx <= 0xffffffffU ? 7 + : 11; } ///////////////////////////////////////////////////////////////////////////// @@ -219,7 +217,7 @@ ecb_inline void need (enc_t *enc, STRLEN len) { - if (ecb_expect_false (enc->cur + len >= enc->end)) + if (ecb_expect_false ((uintptr_t)(enc->end - enc->cur) < len)) { STRLEN cur = enc->cur - (char *)SvPVX (enc->sv); SvGROW (enc->sv, cur + (len < (cur >> 2) ? cur >> 2 : len) + 1); @@ -710,7 +708,7 @@ #define ERR(reason) ERR_DO (err_set (dec, reason)) #define ERR_ERRSV ERR_DO (err_errsv (dec)) -#define WANT(len) if (ecb_expect_false ((UV)(dec->end - dec->cur) < (UV)len)) ERR_DO (err_unexpected_end (dec)) +#define WANT(len) if (ecb_expect_false ((uintptr_t)(dec->end - dec->cur) < (STRLEN)len)) ERR_DO (err_unexpected_end (dec)) #define DEC_INC_DEPTH if (ecb_expect_false (++dec->depth > dec->cbor.max_depth)) ERR (ERR_NESTING_EXCEEDED) #define DEC_DEC_DEPTH --dec->depth