Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87829 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65887 invoked from network); 21 Aug 2015 08:41:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Aug 2015 08:41:24 -0000 Authentication-Results: pb1.pair.com header.from=anatol.php@belski.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=anatol.php@belski.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain belski.net from 85.214.73.107 cause and error) X-PHP-List-Original-Sender: anatol.php@belski.net X-Host-Fingerprint: 85.214.73.107 klapt.com Received: from [85.214.73.107] ([85.214.73.107:37786] helo=h1123647.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FB/20-64560-334E6D55 for ; Fri, 21 Aug 2015 04:41:23 -0400 Received: by h1123647.serverkompetenz.net (Postfix, from userid 1006) id 68A7F23D6299; Fri, 21 Aug 2015 10:41:19 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on h1123647.serverkompetenz.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.5 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable version=3.3.2 Received: from w530phpdev (p579F3AD8.dip0.t-ipconnect.de [87.159.58.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by h1123647.serverkompetenz.net (Postfix) with ESMTPSA id BB16C23D6003; Fri, 21 Aug 2015 10:41:17 +0200 (CEST) To: "'Dmitry Stogov'" , "'Xinchen Hui'" , "'Nikita Popov'" , "'Pierre Joye'" , "'Bob Weinand'" , "'Jakub Zelenka'" , "'Matt Wilmas'" Cc: Date: Fri, 21 Aug 2015 10:41:25 +0200 Message-ID: <02a601d0dbed$2c828df0$8587a9d0$@belski.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 15.0 Thread-Index: AdDb7P24G+CmE7TdS6SVFR6IMBKDBQ== Content-Language: en-us Subject: Overflow checks and integral vars comparison From: anatol.php@belski.net ("Anatol Belski") 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; } Compiler would eliminate the branch automatically on 32-bit and ILP64. Some other macros to do signed/unsigned comparison, these can be extended. #define ZEND_SIZE_T_GT_ZEND_LONG(size, zlong) ((zlong) < 0 || (size) > (size_t)(zlong)) #define ZEND_SIZE_T_GTE_ZEND_LONG(size, zlong) ((zlong) < 0 || (size) >= (size_t)(zlong)) #define ZEND_SIZE_T_LT_ZEND_LONG(size, zlong) ((zlong) >= 0 && (size) < (size_t)(zlong)) #define ZEND_SIZE_T_LTE_ZEND_LONG(size, zlong) ((zlong) >= 0 && (size) <= (size_t)(zlong)) IMHO these and maybe more are missing after the 64-bit RFC. Do you think they would make sense? Or would make sense now, or later in master? Thanks Anatol