From 07014979c1884d69467b3879171c6d69b39ab661 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Wed, 21 Sep 2011 22:20:33 +0200 Subject: [PATCH] Fix possible W->client = NULL in generated client funcs --- wmfs2/src/client.c | 29 +++++++++++++++-------------- wmfs2/src/client.h | 7 ++++--- wmfs2/src/tag.c | 4 ++-- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/wmfs2/src/client.c b/wmfs2/src/client.c index c581c9f..d8d51bf 100644 --- a/wmfs2/src/client.c +++ b/wmfs2/src/client.c @@ -22,20 +22,22 @@ void uicb_client_resize_##D(Uicb cmd) \ client_fac_resize(W->client, D, ATOI(cmd)); \ } -#define CLIENT_ACTION_DIR(A, D) \ -void uicb_client_##A##_##D(Uicb cmd) \ -{ \ - (void)cmd; \ - if(W->client) \ - client_##A(client_next_with_pos(W->client, D)); \ +#define CLIENT_ACTION_DIR(A, D) \ +void uicb_client_##A##_##D(Uicb cmd) \ +{ \ + (void)cmd; \ + struct client *c; \ + if(W->client && (c = client_next_with_pos(W->client, D))) \ + client_##A(c); \ } -#define CLIENT_ACTION_LIST(A, L) \ -void uicb_client_##A##_##L(Uicb cmd) \ -{ \ - (void)cmd; \ - if(W->client) \ - client_##A(client_##L(W->client)); \ +#define CLIENT_ACTION_LIST(A, L) \ +void uicb_client_##A##_##L(Uicb cmd) \ +{ \ + (void)cmd; \ + struct client *c; \ + if(W->client && (c = client_##L(W->client))) \ + client_##A(c); \ } /* uicb_client_resize_dir() */ @@ -122,7 +124,7 @@ client_next_with_pos(struct client *bc, Position p) { struct client *c; int x, y; - const static char scanfac[PositionLast] = { +10, -10, 0, 0 }; + const static char scanfac[PositionLast] = { +1, -1, 0, 0 }; /* * Set start place of pointer (edge with position @@ -421,7 +423,6 @@ client_remove(struct client *c) XSetErrorHandler(wmfs_error_handler); free(c); - c = NULL; } void diff --git a/wmfs2/src/client.h b/wmfs2/src/client.h index 91b2e8c..cc5134c 100644 --- a/wmfs2/src/client.h +++ b/wmfs2/src/client.h @@ -54,10 +54,11 @@ client_next(struct client *c) static inline struct client* client_prev(struct client *c) { - struct client *nc, *cc = SLIST_FIRST(&c->tag->clients); + struct client *cc; - while((nc = SLIST_NEXT(cc, tnext)) && nc != c) - cc = nc; + for(cc = SLIST_FIRST(&c->tag->clients); + SLIST_NEXT(cc, tnext) && SLIST_NEXT(cc, tnext) != c; + cc = SLIST_NEXT(cc, tnext)); return cc; } diff --git a/wmfs2/src/tag.c b/wmfs2/src/tag.c index 87bae89..9b90b9f 100644 --- a/wmfs2/src/tag.c +++ b/wmfs2/src/tag.c @@ -91,10 +91,10 @@ tag_client(struct tag *t, struct client *c) layout_split_arrange_closed(c); + SLIST_REMOVE(&c->tag->clients, c, client, tnext); + if(c->tag->sel == c || W->client == c) client_focus(client_next(c)); - - SLIST_REMOVE(&c->tag->clients, c, client, tnext); } /*