From 3bf3d3722764771df32233b0443035033b8153f8 Mon Sep 17 00:00:00 2001 From: Ivan Kanakarakis Date: Sat, 30 Jun 2012 20:06:04 +0300 Subject: rework move_up and move_down functions - should check for existance of at least two clients bugfix: this is a null dereference bug that would segfault monsterwm if one tried to move a client up or down while there were no clients this was introduced by mistake when the prev_client function was introduced; now prevclient see commit: 0a900d49 --- monsterwm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monsterwm.c b/monsterwm.c index 0c55e0d..31d41f3 100644 --- a/monsterwm.c +++ b/monsterwm.c @@ -575,9 +575,9 @@ void monocle(int hh, int cy) { /* move the current client, to current->next * and current->next to current client's position */ void move_down(void) { + if (!curr || !head->next) return; /* p is previous, c is current, n is next, if current is head n is last */ Client *p = prevclient(curr), *n = (curr->next) ? curr->next:head; - if (!p) return; /* * if c is head, swapping with n should update head to n * [c]->[n]->.. ==> [n]->[c]->.. @@ -612,9 +612,9 @@ void move_down(void) { /* move the current client, to the previous from current and * the previous from current to current client's position */ void move_up(void) { + if (!curr || !head->next) return; /* p is previous from current or last if current is head */ Client *pp = NULL, *p = prevclient(curr); - if (!p) return; /* pp is previous from p, or null if current is head and thus p is last */ if (p->next) for (pp = head; pp && pp->next != p; pp = pp->next); /* -- cgit v1.3.1