Re: com php-src: fix negating an unsigned: Zend/zend_operators.h
| From: | Anatol Belski | Date: | Tue, 16 Sep 2014 03:15:41 +0000 |
| Subject: | Re: com php-src: fix negating an unsigned: Zend/zend_operators.h | ||
| References: | 1 2 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-81670@lists.php.net to get a copy of this message | ||
Hi Nikita,
On Mon, September 15, 2014 22:02, Nikita Popov wrote:
> On Mon, Sep 15, 2014 at 7:46 PM, Anatol Belski <ab@php.net> wrote:
>
>
>> Commit: e0ff5238c5d744509f93aaf914e23f17d51c5ae3
>> Author: Anatol Belski <ab@php.net> Mon, 15 Sep 2014 17:48:15
>> +0200
>> Parents: 383a0773ff27cf57b94fe11d2f825b00cff88714
>> Branches: master
>>
>>
>> Link:
>>
>> http://git.php.net/?p=php-src.git;a=commitdiff;h=e0ff5238c5d744509f93aaf
>> 914e23f17d51c5ae3
>>
>>
>> Log:
>> fix negating an unsigned
>>
>> Changed paths:
>> M Zend/zend_operators.h
>>
>>
>>
>> Diff:
>> diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index
>> 41342de..a50e65d 100644
>> --- a/Zend/zend_operators.h
>> +++ b/Zend/zend_operators.h
>> @@ -1036,7 +1036,7 @@ static zend_always_inline void
>> fast_is_not_identical_function(zval *result, zval /* buf points to the
>> END of the buffer */
>> #define _zend_print_signed_to_buf(buf, num, vartype, result) do {
>> \
>> if (num < 0) { \
>> - _zend_print_unsigned_to_buf((buf), -(vartype)(num), vartype,
>> (result)); \
>> + _zend_print_unsigned_to_buf((buf), (~((vartype)(num)) + 1),
>> vartype, (result)); \ *--(result) = '-';
>> \
>> } else {
>> \
>> _zend_print_unsigned_to_buf((buf), (num), vartype, (result));
>> \
>>
>>
>
> Why this change? Unary minus of an unsigned value is a well-defined
> operation, see C89 3.1.2.5c5 or C99 6.2.5c9. Writing it this way seems
> much less clear to me. Unary minus is the operation that we mean here
> semantically.
>
> Nikita
This change is nothing than fixing this warning
http://msdn.microsoft.com/en-us/library/4kh09110.aspx
-x does the same as (~x + 1), so technically no issue. Hopefully no big
issue for PHP as it's hidden behind the internal implementation. I
wouldn't touch it but for the warning fix, maybe one can wrap it somehow.
Actually thinking about a small set of wrappers to compare or do maths
with signed/unsigned safer and warning free.
Regards
Anatol