:: Re: [DNG] int essid_alloc is causin…
Top Pagina
Delete this message
Reply to this message
Auteur: Mat
Datum:  
Aan: dng
Onderwerp: Re: [DNG] int essid_alloc is causing valgrind to report a series of errors
Is there a reason why you need to write such a wrapper around calloc()?
It adds very little since calloc already sets errno. Plus it's a rather
unnatural construct for an allocator to return the allocated buffer this
way.

if ((err = essid_alloc(len, &buf)) != 0)
    handle_error(err);


if (!(buf = calloc(1, len)))
    handle_error(errno);


I didn't follow the discussion, just looking at this code without context.

On 14/10/15 15:37, Edward Bartolo wrote:
> Dear All,
>
> The problem according to my logic seems to be result is used in a
> branch control expression before it is initialised. However, I am
> emailing this to have other opinions.
>
>
> int essid_alloc(
>     size_t length,
>     char ** result
> ) {
>     char * tmp;

>
>     if(length==0 || !result)
>         return EINVAL;

>
>     tmp = (char *) calloc(length, 1);

>
>     if(!tmp)
>         return ENOMEM;

>
>     *result = tmp;

>     
>     return 0;
> }


--
Mat <mat@???>