Hi Anatol,
----- Original Message -----
From: "Anatol Belski"
Sent: Tuesday, August 18, 2015
Hi Matt,
> [...]
>
> The checks with zend_long vars like key_length and iterations are
> impossible
> when ZEND_LONG_MAX == INT_MAX (most if not all 32-bit, I guess). So
> those
> checks should already be removed by the compiler.
>
It's unlikely to be optimized away, key_length is a variable, not a
constant. It is "INT_MAX < variable", unlikely a compiler can predict what
is in the variable, disregarding bitness.
The compiler isn't stupid, and as Jakub says, knows the range (and
signedness). This is a dead simple optimization that only a really bad
compiler wouldn't do! With GCC, the function:
void test(int foo)
{
if (foo > INT_MAX) printf("Overflow!\n");
}
becomes
ret # Just return instruction
> But for the size_t ones, would need to check SIZEOF_SIZE_T > 4 around
> the
> macros or such. Or you could just change in the definition:
>
Are there platforms where sizeof(size_t) <= sizeof(zend_long) ?
All as far as I know (equal, not less; unless zend_long would be made 64-bit
on 32-bit), although I didn't mention anything about that comparison...
By the current info, size_t is same as zend_ulong, so on any given
platform sizeof(size_t) > sizeof(zend_long).
No, on any platform sizeof(size_t) == sizeof(zend_long), never > unless the
condition I just mentioned. But again, I didn't make this comparison...
And almost I were not aware of platforms SIZEOF_SIZE_T < 4 (some 16-bit?)
but they should go by the same scheme, actually.
I was only referring to check SIZEOF_SIZE_T > 4 (SIZEOF_SIZE_T == 8 is used
in other areas) in an #if around the overflow checks of size_t vars (string
length) with INT_MAX if not just changing the macro definition to allow
removal.
Overflow checks of zend_long with INT_MAX will automatically be removed when
appropriate, as established; as will checks of size_t with UINT_MAX.
Regards
Anatol
- Matt
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php