Limit workspace numbers within 0..INT32_MAX
Before this commit, large workspace numbers treated oddly: $ i3-msg 'rename workspace to 1234567890' # displayed in i3bar as `0` $ i3-msg 'rename workspace to 4294967200' $ i3-msg -t get_workspaces | jq '.[]|select(.focused).num' -96 # int32_t overflow $ i3-msg 'rename workspace to 99999999999999999999' $ i3-msg -t get_workspaces | jq '.[]|select(.focused).num' -1 # treated as unnumbered This commit puts a consistent limit on workspace numbers. Now workspaces with numbers beyond INT32_MAX are treated as unnumbered.
This commit is contained in:
10
src/util.c
10
src/util.c
@ -109,14 +109,12 @@ bool layout_from_name(const char *layout_str, layout_t *out) {
|
||||
* interpreted as a "named workspace".
|
||||
*
|
||||
*/
|
||||
long ws_name_to_number(const char *name) {
|
||||
int ws_name_to_number(const char *name) {
|
||||
/* positive integers and zero are interpreted as numbers */
|
||||
char *endptr = NULL;
|
||||
long parsed_num = strtol(name, &endptr, 10);
|
||||
if (parsed_num == LONG_MIN ||
|
||||
parsed_num == LONG_MAX ||
|
||||
parsed_num < 0 ||
|
||||
endptr == name) {
|
||||
errno = 0;
|
||||
long long parsed_num = strtoll(name, &endptr, 10);
|
||||
if (errno != 0 || parsed_num > INT32_MAX || parsed_num < 0 || endptr == name) {
|
||||
parsed_num = -1;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user