summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adrien Schildknecht <adrien+dev@schischi.me>2013-05-01 21:53:00 +0200
committerGravatar Adrien Schildknecht <adrien+dev@schischi.me>2013-05-01 21:53:00 +0200
commit54c82ee7f71d8160e17ec7c4e1fc60e97fa87853 (patch)
treec0d0a0e947b23c729f8ed3da8fef9990831e1716
parente414630f014456ff621d8028d03dd0007a6c0161 (diff)
fix segfault when getting gvim's cwd
-rw-r--r--xcwd.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/xcwd.c b/xcwd.c
index 3046646..f20ed2a 100644
--- a/xcwd.c
+++ b/xcwd.c
@@ -191,15 +191,21 @@ static int readPath(long pid)
static void cwdOfDeepestChild(processes_t p, long pid)
{
int i;
- struct proc_s key, *res = NULL, *lastRes;
+ struct proc_s key = {.ppid = pid}, *res = NULL, *lastRes = NULL;
do {
- lastRes = res;
- key.ppid = pid;
+ if(res) {
+ lastRes = res;
+ key.ppid = res->pid;
+ }
res = (struct proc_s *)bsearch(&key, p->ps, p->n,
sizeof(struct proc_s), ppidCmp);
- pid = res ? res->pid : -1;
- } while(pid != -1);
+ } while(res);
+
+ if(!lastRes) {
+ readPath(pid);
+ return;
+ }
for(i = 0; lastRes != p->ps && (lastRes - i)->ppid == lastRes->ppid; ++i)
if(readPath((lastRes - i)->pid))