Welcome! Log In Create A New Profile

Advanced

[PATCH] BUG/MINOR: Reset errno variable before calling strtol(3)

Posted by Ryabin Sergey 
Sometimes errno != 0 before calling strtol(3)


diff --git a/src/server.c b/src/server.c
index 2f539c99..28340ddb 100644
--- a/src/server.c
+++ b/src/server.c
@@ -2815,6 +2815,7 @@ const char *update_server_addr_port(struct
server *s, const char *addr, const ch
/* check if PORT change is required */
port_change_required = 0;

+ errno = 0;
sign = *port;
new_port = strtol(port, &endptr, 10);
if ((errno != 0) || (port == endptr)) {
On Wed, Jan 11, 2017 at 07:39:55PM +0400, Ryabin Sergey wrote:
> Sometimes errno != 0 before calling strtol(3)
>
>
> diff --git a/src/server.c b/src/server.c
> index 2f539c99..28340ddb 100644
> --- a/src/server.c
> +++ b/src/server.c
> @@ -2815,6 +2815,7 @@ const char *update_server_addr_port(struct
> server *s, const char *addr, const ch
> /* check if PORT change is required */
> port_change_required = 0;
>
> + errno = 0;
> sign = *port;
> new_port = strtol(port, &endptr, 10);
> if ((errno != 0) || (port == endptr)) {

Thank you, I didn't remember about this corner case. I think we should have
a wrapper for strtol which clears errno at the same time.

I've applied your patch and marked it for 1.7.

Willy
Sorry, only registered users may post in this forum.

Click here to login