Re: [VOTE] Abstract Syntax Tree

From: Date: Tue, 19 Aug 2014 09:35:23 +0000
Subject: Re: [VOTE] Abstract Syntax Tree
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-76694@lists.php.net to get a copy of this message
On Tue, Aug 19, 2014 at 11:30 AM, Laruence <laruence@php.net> 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

« previous php.internals (#76694) next »