[FFmpeg-devel] [PATCH] avutil/mem: add av_memdup()

Nicolas George nicolas.george at normalesup.org
Sun Apr 28 14:52:30 CEST 2013


Le nonidi 9 floréal, an CCXXI, Michael Niedermayer a écrit :
>  /**
> + * Duplicate the buffer p.
> + * @param p buffer to be duplicated
> + * @return Pointer to a newly allocated buffer containing a
> + * copy of p or NULL if the buffer cannot be allocated.
> + */
> +void *av_memdup(const void *p, size_t size);

I like the idea. Possibly slightly more practical API:

int av_memdup(void **dst, const void *src, size_t size);

Returns 0 or AVERROR(ENOMEM) -> avoids "ret = AVERROR(ENOMEM);" before "goto
fail;".

dst is unchanged if allocation failed -> avoids using a temp variable.

Optionally: free *dst before overwriting it.

Second option: "if (size == (size_t)-1) size = strlen(src) + 1;".

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130428/0cd0d205/attachment.asc>


More information about the ffmpeg-devel mailing list