]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: check if values are non-NULL before copying (Thanks xeen)
authorMichael Stapelberg <michael@stapelberg.de>
Tue, 18 Nov 2014 07:27:53 +0000 (08:27 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 18 Nov 2014 07:27:53 +0000 (08:27 +0100)
fixes #1397

src/bindings.c

index 0bda6019187f6f1916ac93e1b86d27aaa079384f..70d274a74c28ac2af08ce26aa238719f75a83e30 100644 (file)
@@ -386,10 +386,14 @@ void check_for_duplicate_bindings(struct context *context) {
 static Binding *binding_copy(Binding *bind) {
     Binding *ret = smalloc(sizeof(Binding));
     *ret = *bind;
-    ret->symbol = strdup(bind->symbol);
-    ret->command = strdup(bind->command);
-    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);
+    if (bind->symbol != NULL)
+        ret->symbol = strdup(bind->symbol);
+    if (bind->command != NULL)
+        ret->command = strdup(bind->command);
+    if (bind->translated_to != NULL) {
+        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);
+    }
     return ret;
 }