From 7100d32971e84dbbef19da0043135b0c14595576 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 14 Mar 2011 23:14:40 +0100 Subject: [PATCH] cmdparse: correctly parse con_id/id (fixes warning) --- src/cmdparse.y | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) 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 { -- 2.39.5