Should ngx_atoi and ngx_atof functions change their signature?!

Wandenberg Peixoto wandenberg at gmail.com
Thu Dec 10 16:55:32 UTC 2015


Hi,

today I realized a possible problem on the ngx_atoi and ngx_atof functions
(may be on all ngx_ato* functions).

There is no way to distinguish between an error and a valid "-1" string.

For instance,

ngx_str_t some_string = ngx_string("-1");
ngx_int_t x = ngx_atoi(some_string.data, some_string.len);

if (x == NGX_ERROR) {
  ngx_log_debug(NGX_LOG_DEBUG, ngx_cycle->log, 0, "ERROR");
} else {
  ngx_log_debug(NGX_LOG_DEBUG, ngx_cycle->log, 0, "SUCCESS %d", x);
}

this code will produce an "ERROR" as output instead of "SUCCESS -1".
The same result as if the some_string had a value like "xyz".

I know that this is unlikely to happen that you have a string with "-1",
but it is possible.

What do you think about change these function signature, or add a new one,
to receive the output as a parameter something like

ngx_int_t
ngx_atoi(u_char *line, size_t n, ngx_int_t *result)

using the "result" parameter to store the parsed value and return NGX_OK or
NGX_ERROR.

Kind regards,
Wandenberg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20151210/ec71fd1a/attachment.html>


More information about the nginx-devel mailing list