[PATCH] zend_operators DVAL_TO_LVAL fix

From: Date: Fri, 27 Aug 2004 12:25:50 +0000
Subject: [PATCH] zend_operators DVAL_TO_LVAL fix
Groups: php.internals 
Request: Send a blank email to internals+get-12420@lists.php.net to get a copy of this message
The DVAL_TO_LVAL macro is quite weird, I'm not sure exactly what it's supposed to be doing but it probably isn't doing it. If the integral part of d is outside the range of a long, the conversion has undefined behaviour by the C99 standard; an explicit cast makes no difference AFAICT. GCC on IA64 does wierd things with this macro, though I think there's a GCC bug involved there too. This fixes the macro to have well-defined behaviour for all values of 'd', and avoids triggering the GCC bug on IA64 to boot (both PHP users on that platform will be happy): Index: Zend/zend_operators.c =================================================================== RCS file: /repository/ZendEngine2/zend_operators.c,v retrieving revision 1.194 diff -u -r1.194 zend_operators.c --- Zend/zend_operators.c 19 Jul 2004 07:19:02 -0000 1.194 +++ Zend/zend_operators.c 27 Aug 2004 12:15:12 -0000 @@ -183,7 +183,15 @@ } -#define DVAL_TO_LVAL(d, l) (l) = (d) > LONG_MAX ? (unsigned long) (d) : (long) (d) +#define DVAL_TO_LVAL(d, l) do { \ + if ((d) > LONG_MAX) { \ + l = LONG_MAX; \ + } else if ((d) < LONG_MIN) { \ + l = LONG_MIN; \ + } else { \ + l = (d); \ + } \ +} while (0) #define zendi_convert_to_long(op, holder, result) \ if (op==result) { \

« previous php.internals (#12420) next »