Bug #47424 [Opn->Csd]: not operator does a C cast to long which is different to other ops

From: Date: Wed, 13 Jul 2016 13:52:34 +0000
Subject: Bug #47424 [Opn->Csd]: not operator does a C cast to long which is different to other ops
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202282@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=47424&edit=1 ID: 47424 Updated by: dmitry@php.net Reported by: d_kelsey at uk dot ibm dot com Summary: not operator does a C cast to long which is different to other ops -Status: Open +Status: Closed Type: Bug Package: Scripting Engine problem Operating System: Linux 64Bit PHP Version: 5.2CVS-2009-02-17 (CVS) -Assigned To: +Assigned To: dmitry Block user comment: N Private report: N New Comment: The bug was fixed long time ago in PHP-5.3. Previous Comments: ------------------------------------------------------------------------ [2010-05-05 20:36:32] whatrevolution at yahoo dot com Bug OP's test, result: int 9223372036854775807 int 9223372036854775807 PHP Version 5.2.10-2ubuntu6.4 System Linux 2.6.31-20-generic x86_64 Build Date Jan 6 2010 22:36:47 Server API Apache 2.0 Handler PHP API 20041225 PHP Extension 20060613 Zend Extension 220060519 Debug Build no Thread Safety disabled Zend Memory Manager enabled Apache/2.2.12 (Ubuntu) ------------------------------------------------------------------------ [2009-02-17 14:05:01] d_kelsey at uk dot ibm dot com Description: ------------ In zend_operators.c the function ZEND_API int bitwise_not_function(..) handles a double by doing a c cast to a long "if (op1->type == IS_DOUBLE) { op1->value.lval = (long) op1->value.dval; op1->type = IS_LONG; }" but all other operators use the zendi_convert_to_long() macro so not isn't consistent with the other operators. this can result in an unexpected value as shown in the test case Reproduce code: --------------- <?php define("MAX_64Bit", 9223372036854775807); $e = (MAX_64Bit + 1); $f = (int)$e; var_dump(~(MAX_64Bit + 1)); var_dump(~$f); ?> Expected result: ---------------- int(-9223372036854775808) int(-9223372036854775808) Actual result: -------------- int(9223372036854775807) int(-9223372036854775808) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=47424&edit=1

« previous php.bugs (#202282) next »