<div dir="ltr">Ops.<div><br></div><div>Sorry, I didn't realize that it only deals with positive numbers.</div><div>The return type as ngx_int_t tricked me, and I didn't checked the use case as "-2".</div><div><br></div><div>Sorry again.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 10, 2015 at 3:01 PM, Valentin V. Bartenev <span dir="ltr"><<a href="mailto:vbart@nginx.com" target="_blank">vbart@nginx.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Thursday 10 December 2015 14:55:32 Wandenberg Peixoto wrote:<br>
> Hi,<br>
><br>
> today I realized a possible problem on the ngx_atoi and ngx_atof functions<br>
> (may be on all ngx_ato* functions).<br>
><br>
> There is no way to distinguish between an error and a valid "-1" string.<br>
><br>
> For instance,<br>
><br>
> ngx_str_t some_string = ngx_string("-1");<br>
> ngx_int_t x = ngx_atoi(some_string.data, some_string.len);<br>
><br>
> if (x == NGX_ERROR) {<br>
> ngx_log_debug(NGX_LOG_DEBUG, ngx_cycle->log, 0, "ERROR");<br>
> } else {<br>
> ngx_log_debug(NGX_LOG_DEBUG, ngx_cycle->log, 0, "SUCCESS %d", x);<br>
> }<br>
><br>
> this code will produce an "ERROR" as output instead of "SUCCESS -1".<br>
> The same result as if the some_string had a value like "xyz".<br>
><br>
> I know that this is unlikely to happen that you have a string with "-1",<br>
> but it is possible.<br>
><br>
> What do you think about change these function signature, or add a new one,<br>
> to receive the output as a parameter something like<br>
><br>
> ngx_int_t<br>
> ngx_atoi(u_char *line, size_t n, ngx_int_t *result)<br>
><br>
> using the "result" parameter to store the parsed value and return NGX_OK or<br>
> NGX_ERROR.<br>
><br>
<br>
</span>What makes you think that these functions are able to parse negative numbers?<br>
<br>
wbr, Valentin V. Bartenev<br>
<br>
_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
</blockquote></div><br></div>