Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87830 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73676 invoked from network); 21 Aug 2015 09:21:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Aug 2015 09:21:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.175 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 209.85.217.175 mail-lb0-f175.google.com Received: from [209.85.217.175] ([209.85.217.175:36095] helo=mail-lb0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 26/C0-64560-D8DE6D55 for ; Fri, 21 Aug 2015 05:21:17 -0400 Received: by lbbpu9 with SMTP id pu9so39881678lbb.3 for ; Fri, 21 Aug 2015 02:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=G/AYB1URDYJ5HBPabtipqDKPM3aWgdN1ltMk2LiULAI=; b=hiO0+zqlLIoTaLFOT5oo7vd79H6h6lvqy1q7c9Vs5/5znOA61BFKDCiOCacrFa19qJ BU8f9pDHBcX8B18xkVaFc0dHwtn9BSC4Sz8rlB8PXTPPwuNxVh3wK55Kycuzx1k6cJDi yLCukPoPOFM/lDH3KXoTX3L2+JfhR4CXLQt7Yya2/ksebPOM92YLoJsq+/JbWuMow8Wq DJIiqBF+8a9tIkSBAmiYzcWwQx0xzHkXODjMeaO36hzB+GRaXi437NK+z1UVg8iLlO9R iwH6fy35PSDCsQ1YWGhYhc3M7LmsXcm6FNrd3zqj7jM1gFJJvCxEWM/Y0cTh7nAnjtSM Pl3Q== MIME-Version: 1.0 X-Received: by 10.152.42.170 with SMTP id p10mr6808840lal.39.1440148874720; Fri, 21 Aug 2015 02:21:14 -0700 (PDT) Received: by 10.25.200.196 with HTTP; Fri, 21 Aug 2015 02:21:14 -0700 (PDT) In-Reply-To: <02a601d0dbed$2c828df0$8587a9d0$@belski.net> References: <02a601d0dbed$2c828df0$8587a9d0$@belski.net> Date: Fri, 21 Aug 2015 05:21:14 -0400 Message-ID: To: Anatol Belski Cc: Dmitry Stogov , Xinchen Hui , Nikita Popov , Pierre Joye , Bob Weinand , Jakub Zelenka , Matt Wilmas , PHP Internals Content-Type: multipart/alternative; boundary=001a11c34c7819fe7b051dceca98 Subject: Re: [PHP-DEV] Overflow checks and integral vars comparison From: theanomaly.is@gmail.com (Sherif Ramadan) --001a11c34c7819fe7b051dceca98 Content-Type: text/plain; charset=UTF-8 Maybe I'm missing something here, but how do these macros detect overflow exactly? If the check is done on the actual result and not the operands then it's not a good overflow check. Additionally, why wouldn't overflow checks be needed on 32-bit architecture, or any other architecture for that matter? Integers can overflow there too. On Fri, Aug 21, 2015 at 4:41 AM, Anatol Belski 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; > } > > 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 > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a11c34c7819fe7b051dceca98--