From: Michael Stapelberg Date: Mon, 14 Mar 2011 22:14:40 +0000 (+0100) Subject: cmdparse: correctly parse con_id/id (fixes warning) X-Git-Tag: tree-pr3~125 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7100d32971e84dbbef19da0043135b0c14595576;p=i3%2Fi3 cmdparse: correctly parse con_id/id (fixes warning) --- diff --git a/src/cmdparse.y b/src/cmdparse.y index 476f7977..37605bb8 100644 --- a/src/cmdparse.y +++ b/src/cmdparse.y @@ -13,6 +13,7 @@ #include #include #include +#include #include "all.h" @@ -259,16 +260,32 @@ criteria: | TOK_CON_ID '=' STR { printf("criteria: id = %s\n", $3); - /* TODO: correctly parse number */ - current_match.con_id = (Con*)atoi($3); - printf("id as int = %p\n", current_match.con_id); + char *end; + long parsed = strtol($3, &end, 10); + if (parsed == LONG_MIN || + parsed == LONG_MAX || + parsed < 0 || + (end && *end != '\0')) { + ELOG("Could not parse con id \"%s\"\n", $3); + } else { + current_match.con_id = (Con*)parsed; + printf("id as int = %p\n", current_match.con_id); + } } | TOK_ID '=' STR { printf("criteria: window id = %s\n", $3); - /* TODO: correctly parse number */ - current_match.id = atoi($3); - printf("window id as int = %d\n", current_match.id); + char *end; + long parsed = strtol($3, &end, 10); + if (parsed == LONG_MIN || + parsed == LONG_MAX || + parsed < 0 || + (end && *end != '\0')) { + ELOG("Could not parse window id \"%s\"\n", $3); + } else { + current_match.id = parsed; + printf("window id as int = %d\n", current_match.id); + } } | TOK_MARK '=' STR {