[PATCH 08/11] Unit: avoided needlessly setting lib in nxt_unit_shm_open().

Alejandro Colomar alx.manpages at gmail.com
Thu Jun 16 15:57:30 UTC 2022



On 6/16/22 03:00, Andrew Clayton wrote:
> As was pointed out by the cppcheck[0] static code analysis utility, lib
> was being set in nxt_unit_shm_open() regardless of platform when in fact
> it's only used when (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN).
> 
> Move the variable declaration & definition to be within the
> 
>    #if (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN)
> 
> block.
> 
> [0]: https://cppcheck.sourceforge.io/

Reviewed-by: Alejandro Colomar <alx.manpages at gmail.com>

> ---
>   src/nxt_unit.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/src/nxt_unit.c b/src/nxt_unit.c
> index 4be0906..9baa680 100644
> --- a/src/nxt_unit.c
> +++ b/src/nxt_unit.c
> @@ -3813,13 +3813,12 @@ static int
>   nxt_unit_shm_open(nxt_unit_ctx_t *ctx, size_t size)
>   {
>       int              fd;
> -    nxt_unit_impl_t  *lib;
> -
> -    lib = nxt_container_of(ctx->unit, nxt_unit_impl_t, unit);
>   
>   #if (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN)
>       char             name[64];
> +    nxt_unit_impl_t  *lib;
>   
> +    lib = nxt_container_of(ctx->unit, nxt_unit_impl_t, unit);
>       snprintf(name, sizeof(name), NXT_SHM_PREFIX "unit.%d.%p",
>                lib->pid, (void *) (uintptr_t) pthread_self());
>   #endif

-- 
Alejandro Colomar
<http://www.alejandro-colomar.es/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://mailman.nginx.org/pipermail/unit/attachments/20220616/e8a8fae8/attachment.bin>


More information about the unit mailing list