commit cd2c0a4e31e3a5a58998684c39316f1f36589b37
parent e57f9df6d6d5f768d947d0d00963468849bc41be
Author: Bastien Dejean <nihilhill@gmail.com>
Date: Sat, 5 Jan 2013 17:24:01 +0100
Don't rely on *sscanf* for parsing sequences
Diffstat:
3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/keys.c b/keys.c
@@ -2518,6 +2518,16 @@ bool parse_modifier(char *name, uint16_t *modfield)
return false;
}
+bool parse_sequence(char *name, char *seq)
+{
+ if (name[0] == SEQ_BEGIN && name[strlen(name) - 1] == SEQ_END) {
+ strncpy(seq, name + 1, strlen(name) - 2);
+ seq[strlen(name) - 2] = '\0';
+ return true;
+ }
+ return false;
+}
+
xcb_event_mask_t key_to_mouse(xcb_event_mask_t event_mask)
{
if (event_mask == XCB_KEY_PRESS)
@@ -2537,8 +2547,8 @@ void get_lock_fields(void)
void unfold_hotkeys(char *keysym_seq, uint16_t modfield, xcb_event_mask_t event_mask, char *command)
{
- char *begin = strchr(command, SEQ_BEGIN[0]);
- char *end = strrchr(command, SEQ_END[0]);
+ char *begin = strchr(command, SEQ_BEGIN);
+ char *end = strrchr(command, SEQ_END);
if (begin == NULL || end == NULL || ((end - begin - 1) < SEQ_MIN_LEN)) {
warn("Invalid sequence for command '%s'.\n", command);
return;
diff --git a/keys.h b/keys.h
@@ -11,8 +11,8 @@
#define START_COMMENT '#'
#define TOK_SEP "+ \n"
#define SEQ_SEP ","
-#define SEQ_BEGIN "{"
-#define SEQ_END "}"
+#define SEQ_BEGIN '{'
+#define SEQ_END '}'
void grab(void);
void grab_key_button(xcb_keycode_t, xcb_button_t, uint16_t);
@@ -23,6 +23,7 @@ xcb_keycode_t *keycodes_from_keysym(xcb_keysym_t);
bool parse_key(char *, xcb_keysym_t *);
bool parse_button(char *, xcb_button_t *);
bool parse_modifier(char *, uint16_t *);
+bool parse_sequence(char *, char *);
xcb_event_mask_t key_to_mouse(xcb_event_mask_t);
void get_lock_fields(void);
void unfold_hotkeys(char *, uint16_t, xcb_event_mask_t, char *);
diff --git a/sxhkd.c b/sxhkd.c
@@ -108,7 +108,7 @@ void load_config(void)
event_mask = XCB_KEY_RELEASE;
name++;
}
- if (!parse_modifier(name, &modfield) && !parse_key(name, &keysym) && !parse_button(name, &button) && !(sscanf(name, SEQ_BEGIN"%s"SEQ_END, keysym_seq) == 1)) {
+ if (!parse_modifier(name, &modfield) && !parse_key(name, &keysym) && !parse_button(name, &button) && !parse_sequence(name, keysym_seq)) {
warn("Unrecognized key name: '%s'.\n", name);
}
} while ((name = strtok(NULL, TOK_SEP)) != NULL);