Welcome! Log In Create A New Profile

Advanced

Re: Should ngx_atoi and ngx_atof functions change their signature?!

December 10, 2015 12:16PM
Ops.

Sorry, I didn't realize that it only deals with positive numbers.
The return type as ngx_int_t tricked me, and I didn't checked the use case
as "-2".

Sorry again.

On Thu, Dec 10, 2015 at 3:01 PM, Valentin V. Bartenev <vbart@nginx.com>
wrote:

> On Thursday 10 December 2015 14:55:32 Wandenberg Peixoto wrote:
> > 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.
> >
>
> What makes you think that these functions are able to parse negative
> numbers?
>
> wbr, Valentin V. Bartenev
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Should ngx_atoi and ngx_atof functions change their signature?!

wandenberg 756 December 10, 2015 11:58AM

Re: Should ngx_atoi and ngx_atof functions change their signature?!

Valentin V. Bartenev 373 December 10, 2015 12:04PM

Re: Should ngx_atoi and ngx_atof functions change their signature?!

wandenberg 597 December 10, 2015 12:16PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 279
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready