Bugfix: check if values are non-NULL before copying (Thanks xeen)

fixes #1397
This commit is contained in:
Michael Stapelberg 2014-11-18 08:27:53 +01:00
parent 8d031bfbf8
commit ef9b081a3e
1 changed files with 8 additions and 4 deletions

View File

@ -386,10 +386,14 @@ void check_for_duplicate_bindings(struct context *context) {
static Binding *binding_copy(Binding *bind) { static Binding *binding_copy(Binding *bind) {
Binding *ret = smalloc(sizeof(Binding)); Binding *ret = smalloc(sizeof(Binding));
*ret = *bind; *ret = *bind;
if (bind->symbol != NULL)
ret->symbol = strdup(bind->symbol); ret->symbol = strdup(bind->symbol);
if (bind->command != NULL)
ret->command = strdup(bind->command); ret->command = strdup(bind->command);
if (bind->translated_to != NULL) {
ret->translated_to = smalloc(sizeof(xcb_keycode_t) * bind->number_keycodes); ret->translated_to = smalloc(sizeof(xcb_keycode_t) * bind->number_keycodes);
memcpy(ret->translated_to, bind->translated_to, sizeof(xcb_keycode_t) * bind->number_keycodes); memcpy(ret->translated_to, bind->translated_to, sizeof(xcb_keycode_t) * bind->number_keycodes);
}
return ret; return ret;
} }