Hi Anatol, On Fri, Aug 21, 2015 at 9:41 AM, Anatol Belski <anatol....@belski.net> wrote:
> Hi, > > Resending this as missed internals at the start. > > I was lately rethinking some part of the 64-bit RFC, and also seeing now > Jakub's work on catching overflows in ext/openssl and Matt Williams > suggestions on it (which was going a bit more global over it). So I came up > with these macros with two goals > > - standardize the overflow checks > - do actualy checks only on architectures where it's needed > - simplify the checks where external libs (openssl, libxml, etc.) use firm > datatypes like int > > #if SIZEOF_INT == SIZEOF_ZEND_LONG > # define ZEND_LONG_INT_OVFL(zl) (0) > # define ZEND_LONG_INT_UDFL(zl) (0) > #else > # define ZEND_LONG_INT_OVFL(zlong) ((zlong) > (zend_long)INT_MAX) # define > ZEND_LONG_INT_UDFL(zlong) ((zlong) < (zend_long)INT_MIN) #endif > > #define ZEND_SIZE_T_INT_OVFL(size) ((size) > (size_t)INT_MAX) > > So having it like > > If (ZEND_LONG_INT_OVFL(x)) { > return; > } > > I think this makes and sense and it's a good start. What I think would be even more useful is to have such checks in ZPP. The thing is that usual use case for libs where the most used integer type is int (e.g. openssl) is following: 1. Get zend_long "l" resp. string "s" with size_t len from zend_parse_paramters 2. check if it doesn't overflow INT_MAX or when needed INT_MIN 3. cast it to int and pass the value to the lib function If we have such functionality in ZPP, then it would be much simpler. I would imaging adding "i" for int and something like "q" (maybe different letter :) ) for string with int size. It would be basically the same as "l" and "s" but there would be an extra int overflow check which would fail if it's bigger / smaller. That would be very useful IMHO. Cheers Jakub