[PATCH 1 of 2] Core: simplified error handling in ngx_pstrdup()

Maxim Dounin mdounin at mdounin.ru
Sun Aug 3 20:22:45 UTC 2014


Hello!

On Sat, Aug 02, 2014 at 12:30:47PM +0900, Tatsuhiko Kubo wrote:

> # HG changeset patch
> # User Tatsuhiko Kubo <cubicdaiya at gmail.com>
> # Date 1406949459 -32400
> #      Sat Aug 02 12:17:39 2014 +0900
> # Node ID 21d53d2ef2cd35967df5f788589e5470d650dad3
> # Parent  f87afb46ccd26fccc7ed55ca8a7ef89c6256c3f2
> Core: simplified error handling in ngx_pstrdup().
> 
> diff -r f87afb46ccd2 -r 21d53d2ef2cd src/core/ngx_string.c
> --- a/src/core/ngx_string.c	Fri Aug 01 20:04:14 2014 +0900
> +++ b/src/core/ngx_string.c	Sat Aug 02 12:17:39 2014 +0900
> @@ -59,12 +59,10 @@ ngx_pstrdup(ngx_pool_t *pool, ngx_str_t 
>      u_char  *dst;
>  
>      dst = ngx_pnalloc(pool, src->len);
> -    if (dst == NULL) {
> -        return NULL;
> +    if (dst) {
> +        ngx_memcpy(dst, src->data, src->len);
>      }
>  
> -    ngx_memcpy(dst, src->data, src->len);
> -
>      return dst;
>  }

No, thanks.  Explicit error handling is better, even if it 
requires couple of additional lines.

The same for the second patch.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx-devel mailing list