[PATCH v3 12/12] Static: multiple paths in the "index" option

Alejandro Colomar (man-pages) alx.manpages at gmail.com
Sun Dec 19 01:49:03 UTC 2021


On 12/19/21 02:30, Alejandro Colomar wrote:
> diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c
> index 16744f2..91bf26e 100644
> --- a/src/nxt_http_static.c
> +++ b/src/nxt_http_static.c
> @@ -123,14 +125,23 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
>           nxt_conf_set_string_dup(acf->index, mp, &default_index);
>       }
>   
> -    nxt_conf_get_string(acf->index, &str);
> -
> -    var = nxt_var_compile(&str, mp, 1);
> -    if (nxt_slow_path(var == NULL)) {
> +    conf->nindices = nxt_conf_array_elements_count(acf->index);
> +    conf->indices = nxt_mp_zget(mp, sizeof(*conf->indices) * conf->nindices);

BTW, I forgot to comment something here:

I see that you always use 'p = xxallocxx(sizeof(type));' instead of 'p = 
xxallocxx(sizeof(*p));'.  I find using the variable instead of it's type 
much more safe, since if you change the type of the variable and you 
forget to change every malloc call related to it, you have a new shiny 
bug, while with this code, it is updated automatically (of course a 
variable name change could produce a bug too, but normally renaming a 
variable will result in the code not compiling).  I guess some compiler 
warning may be able to catch this, but I think it's safer to not use 
that construct at all.  See also:
<https://stackoverflow.com/a/605858/6872717>

What do you think about it?

Thanks,
Alex

-- 
Alejandro Colomar
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/


More information about the unit mailing list