Igor Sysoev igor at
Tue Dec 3 07:46:35 UTC 2013

On Dec 3, 2013, at 3:44 , Dean Pucsek wrote:

> Hello,
> While reading through the source code for nginx I came across the following two lines in ngx_config.h 
> #define NGX_INT32_LEN   (sizeof("-2147483648") - 1)
> #define NGX_INT64_LEN   (sizeof("-9223372036854775808") - 1)
> I was wondering if someone could explain the intention of these lines to me because it is not clear.  My understanding is that using sizeof() on a string will return the number of characters in that string.  Conversely, I get the feeling these lines are supposed to somehow act as replacements for INT32_MAX and INT64_MAX in stdint.h.
> Looking at code where these #define’s are used doesn’t really help clarify things either.  For example, in nginx.c there is:
>     var = ngx_alloc(sizeof(NGINX_VAR)
>                     + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2,
>                     cycle->log);
> The code clearly allocates memory, but it’s not clear why the allocation is a multiple of NGX_INT32_LEN (or why we’re adding 1, or 2 for that matter).
> Any direction would be much appreciated.

They used to allocate memory for string representation of number.
In this particular case 1 is for ";", 2 is for "=" and trailing zero.

Igor Sysoev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx-devel mailing list