Re: [PHP-DEV] [VOTE] Abstract Syntax Tree
[email protected] (Pierre Joye)
| Newsgroups | php.internals |
|---|---|
| Message-ID | <CAEZPtU4y5GN+f_FWmz1TNnaBxJ-akJ1XsMQqVCPxBkqBPt+CfA@mail.gmail.com> |
On Tue, Aug 19, 2014 at 11:30 AM, Laruence <[email protected]> wrote: > Hey: > > a fix could be: > diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c > index eb35a51..f738e34 100644 > --- a/Zend/zend_ast.c > +++ b/Zend/zend_ast.c > @@ -33,11 +33,11 @@ static inline void *zend_ast_realloc(void *old, > size_t old_size, size_t new_size > return new; > } > > -size_t zend_ast_size(zend_uint children) { > +size_t zend_ast_size(int children) { > return sizeof(zend_ast) + sizeof(zend_ast *) * (children - 1); > } > > -size_t zend_ast_list_size(zend_uint children) { > +size_t zend_ast_list_size(int children) { > return sizeof(zend_ast_list) + sizeof(zend_ast *) * (children - 1); > } > > > my compiler must take (children -1) as a unsigned It does, the result of the expression will be. But the fix is imo wrong. A size cannot be negative, per se. It would be cleaner to do: size_t zend_ast_size(int children) { if (children > 0) { return sizeof(zend_ast) + sizeof(zend_ast *) * (children - 1); } else { // 0 or sizeof(zend_ast) + sizeof(zend_ast *) if at least one elem is allocated (NULLed). } } Cheers, -- Pierre @pierrejoye | http://www.libgd.org