From: Michael D. Lowis Date: Mon, 7 Jan 2019 18:05:43 +0000 (-0500) Subject: fixed a bug where windows get registered with null paths and those paths are matched... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=bb05fcc9d284bc222494ffeaff37b13dc1b67c80;p=projs%2Ftide.git fixed a bug where windows get registered with null paths and those paths are matched causing a segfault --- diff --git a/TODO.md b/TODO.md index 5d0835a..03222f8 100644 --- a/TODO.md +++ b/TODO.md @@ -12,7 +12,6 @@ * tide: Line - Get the current line number(s) containing the selection * tide: Kill - add a 'Kill' tag to kill the most recent job * tide: gap buffer does not handle UTF-8 currently -* edit: hangs after launching an empty tide instance then trying to open already open file ## BACKLOG diff --git a/src/registrar.c b/src/registrar.c index 9b69ee7..b6c6f62 100644 --- a/src/registrar.c +++ b/src/registrar.c @@ -1,3 +1,4 @@ +#include #include #include #include "config.h" @@ -24,10 +25,12 @@ char* readprop(XConf* x, Window win, char* prop, size_t* length) { } void win_add(XConf* x, Window id) { + char* path = readprop(x, id, "FILE", 0); + if (!path) return; TWindow* win = calloc(1, sizeof(TWindow)); win->win = id; win->next = Windows; - win->path = readprop(x, id, "FILE", 0); + win->path = path; Windows = win; } @@ -64,7 +67,7 @@ void win_open(XConf* x, Window winid, char* path, char* addr) { if (!path) return; /* search for an existing window */ for (TWindow* win = Windows; win; win = win->next) { - if (!strcmp(win->path, path)) { + if (win->path && !strcmp(win->path, path)) { win_send(x, win->win, x->root, SubstructureRedirectMask|SubstructureNotifyMask, "_NET_ACTIVE_WINDOW", 0); XMapRaised(x->display, win->win); win_send(x, x->self, win->win, 0, "GOTO", strtoul(addr, NULL, 0)); @@ -133,8 +136,14 @@ int daemonize(void) { return 0; } -int main(void) { - if (daemonize() != 0) return 1; +char* ARGV0; +int Foreground = 0; + +int main(int argc, char** argv) { + OPTBEGIN { + case 'F': Foreground = 1; break; + } OPTEND; + if (!Foreground && daemonize() != 0) return 1; XConf x = {0}; x11_init(&x); x11_mkwin(&x, 1, 1, PropertyChangeMask);