Merge pull request #1768 from hwangcc23/atoi2strtol
Fix TODO in src/bindings.c
This commit is contained in:
commit
f76838794d
@ -63,10 +63,11 @@ Binding *configure_binding(const char *bindtype, const char *modifiers, const ch
|
|||||||
|
|
||||||
new_binding->symbol = sstrdup(input_code);
|
new_binding->symbol = sstrdup(input_code);
|
||||||
} else {
|
} else {
|
||||||
// TODO: strtol with proper error handling
|
char *endptr;
|
||||||
new_binding->keycode = atoi(input_code);
|
long keycode = strtol(input_code, &endptr, 10);
|
||||||
|
new_binding->keycode = keycode;
|
||||||
new_binding->input_type = B_KEYBOARD;
|
new_binding->input_type = B_KEYBOARD;
|
||||||
if (new_binding->keycode == 0) {
|
if (keycode == LONG_MAX || keycode == LONG_MIN || keycode < 0 || *endptr != '\0' || endptr == input_code) {
|
||||||
ELOG("Could not parse \"%s\" as an input code, ignoring this binding.\n", input_code);
|
ELOG("Could not parse \"%s\" as an input code, ignoring this binding.\n", input_code);
|
||||||
FREE(new_binding);
|
FREE(new_binding);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -256,10 +257,11 @@ void translate_keysyms(void) {
|
|||||||
|
|
||||||
TAILQ_FOREACH(bind, bindings, bindings) {
|
TAILQ_FOREACH(bind, bindings, bindings) {
|
||||||
if (bind->input_type == B_MOUSE) {
|
if (bind->input_type == B_MOUSE) {
|
||||||
int button = atoi(bind->symbol + (sizeof("button") - 1));
|
char *endptr;
|
||||||
|
long button = strtol(bind->symbol + (sizeof("button") - 1), &endptr, 10);
|
||||||
bind->keycode = button;
|
bind->keycode = button;
|
||||||
|
|
||||||
if (button < 1)
|
if (button == LONG_MAX || button == LONG_MIN || button < 0 || *endptr != '\0' || endptr == bind->symbol)
|
||||||
ELOG("Could not translate string to button: \"%s\"\n", bind->symbol);
|
ELOG("Could not translate string to button: \"%s\"\n", bind->symbol);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user