Re: Re: Convert zval array to char **
| From: | Sara Golemon | Date: | Fri, 22 Jul 2005 17:53:02 +0000 |
| Subject: | Re: Re: Convert zval array to char ** | ||
| References: | 1 2 3 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-2641@lists.php.net to get a copy of this message | ||
> > > array_count = zend_hash_num_elements(arr_hash);
> > >
> > /* Allocate a vector of char* pointers to point at individual
string
> > elements
> > * Leave room for one additional pointer at the end to act as a
> > terminating NULL */
> > ppHashElements = safe_emalloc(array_count, sizeof(char*),
> > sizeof(char*));
> That would be clearer written as:
>
> ppHashElements = safe_emalloc(array_count + 1, sizeof(char*), 0);
>
Sure, but when writing example code I prefer to be as explicit in usage as
possible. The whole point of the safe_*alloc() functions is to avoid weird
carry issues. Is that *ever* going to happen in this instance? No. You'd
need 2^31 elements (assuming 32-bit arch) in the array and that's just not
going to happen in PHP on a system using less than about a 100GB of ram.
But then again.... 640k ought to be enough for anyone....
-Sara