From 8928b5f55de9ad2e13b3f50f9bec5d42221eeb30 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 5 Sep 2011 22:21:10 +0200 Subject: [PATCH] Bugfix: Correctly handle workspace names which do not start with a zero --- src/randr.c | 6 ++++-- src/workspace.c | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/randr.c b/src/randr.c index 6b6cd67d..dd30925b 100644 --- a/src/randr.c +++ b/src/randr.c @@ -447,10 +447,12 @@ void init_ws_for_output(Output *output, Con *content) { if (!exists) { /* Set ->num to the number of the workspace, if the name actually * is a number or starts with a number */ - long parsed_num = strtol(ws->name, NULL, 10); + char *endptr = NULL; + long parsed_num = strtol(ws->name, &endptr, 10); if (parsed_num == LONG_MIN || parsed_num == LONG_MAX || - parsed_num <= 0) + parsed_num < 0 || + endptr == ws->name) ws->num = -1; else ws->num = parsed_num; LOG("Used number %d for workspace with name %s\n", ws->num, ws->name); diff --git a/src/workspace.c b/src/workspace.c index 963fa64b..27899a37 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -49,11 +49,12 @@ Con *workspace_get(const char *num, bool *created) { workspace->name = sstrdup(num); /* We set ->num to the number if this workspace’s name consists only of * a positive number. Otherwise it’s a named ws and num will be -1. */ - - long parsed_num = strtol(num, NULL, 10); + char *endptr = NULL; + long parsed_num = strtol(num, &endptr, 10); if (parsed_num == LONG_MIN || parsed_num == LONG_MAX || - parsed_num < 0) + parsed_num < 0 || + endptr == num) workspace->num = -1; else workspace->num = parsed_num; LOG("num = %d\n", workspace->num); -- 2.39.5