Skip to content

Conversation

@devnexen
Copy link
Member

expects larger type than a unsigned short.

expects larger type than a unsigned short.
@cmb69
Copy link
Member

cmb69 commented Sep 13, 2019

Passing an unsigned short to a function which expects a size_t shouldn't trigger a compiler warning.

@devnexen
Copy link
Member Author

In general indeed but in the macro mentioned there is comparison with larger than unsigned short value.

@cmb69
Copy link
Member

cmb69 commented Sep 13, 2019

Ah, I see. It seems to me that we should use proper literal suffixes for the numeric constants in https://github.com/php/php-src/blob/master/Zend/zend_alloc_sizes.h (and maybe elsewhere). AFAIK, there are none, so casting to size_t there appears to be sensible.

@nikic
Copy link
Member

nikic commented Sep 13, 2019

For the record, the actual warning here is:

/home/nikic/php-src-fuzz/ext/standard/image.c:452:11: error: result of comparison of constant
      2093056 with expression of type 'unsigned short' is always true
      [-Werror,-Wtautological-constant-out-of-range-compare]
        buffer = emalloc(length);
                 ^~~~~~~~~~~~~~~

@cmb69
Copy link
Member

cmb69 commented Sep 13, 2019

Ah, thanks! I understand that this diagnostic can be helpful to catch potential bugs, but it seems to me that in this case the compiler complains about a nice and cheap optimization possibility, and we are considering to remove that. Wouldn't it be more sensible to ignore this warning (maybe telling the compiler about that)?

@nikic
Copy link
Member

nikic commented Sep 13, 2019

This change has no impact on compiler optimization. (In fact the whole ZEND_ALLOCATOR stuff will be optimized away, because the length is not a constant expression.)

@nikic
Copy link
Member

nikic commented Sep 13, 2019

Merged as 711bd0a.

@nikic nikic closed this Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants