From: NeilBrown Date: Mon, 3 Jul 2023 22:38:09 +0000 (+1000) Subject: Always handle pane_register failure immediately. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=92bb713b4f2ec004db545fa153f9285ea9222d2f;p=edlib.git Always handle pane_register failure immediately. Rather then p = pane_register(); if (p) .... Use p = pane_register(); if (!p) return FAIL ... Signed-off-by: NeilBrown --- diff --git a/core-doc.c b/core-doc.c index 1f5b433d..c5b89cfa 100644 --- a/core-doc.c +++ b/core-doc.c @@ -1355,9 +1355,9 @@ static struct pane *doc_attach_assign(struct pane *parent safe, struct pane *doc alloc(dd, pane); p = pane_register(parent, 0, &doc_handle.c, dd); - pane_damaged(p, DAMAGED_VIEW); if (!p) return NULL; + pane_damaged(p, DAMAGED_VIEW); m = point_new(doc); if (!m) { diff --git a/core-editor.c b/core-editor.c index 825971d3..ba87f676 100644 --- a/core-editor.c +++ b/core-editor.c @@ -676,11 +676,12 @@ struct pane *editor_new(void) ei->cmd = ed_handle; ei->cmd.m = &ei->map; ed = pane_register_root(&ei->cmd.c, ei, sizeof(ei)); + if (!ed) + return NULL; + + doc_setup(ed); + log_setup(ed); + window_setup(ed); - if (ed) { - doc_setup(ed); - log_setup(ed); - window_setup(ed); - } return ed; } diff --git a/core-log.c b/core-log.c index 700ef18e..6bc34e18 100644 --- a/core-log.c +++ b/core-log.c @@ -437,6 +437,9 @@ static void log_init(struct pane *ed safe) INIT_LIST_HEAD(&log_doc->log); log_pane = doc_register(ed, &log_handle.c, log_doc); + if (!log_pane) + return; + fname = getenv("EDLIB_LOG"); if (!fname || !*fname) return; diff --git a/doc-dir.c b/doc-dir.c index b58c9863..04efd4ae 100644 --- a/doc-dir.c +++ b/doc-dir.c @@ -198,9 +198,10 @@ DEF_CMD(dir_new) INIT_LIST_HEAD(&dr->ents); dr->fname = NULL; p = doc_register(ci->home, &dir_handle.c, dr); - if (p) - return comm_call(ci->comm2, "callback:doc", p); - return Efail; + if (!p) + return Efail; + + return comm_call(ci->comm2, "callback:doc", p); } DEF_CMD(dir_new2) @@ -1218,8 +1219,10 @@ DEF_CMD(dirview_clone) struct pane *p; p = pane_register(ci->focus, 0, &dirview_handle.c); - if (p) - pane_clone_children(ci->home, p); + if (!p) + return Efail; + + pane_clone_children(ci->home, p); return 1; } diff --git a/doc-list.c b/doc-list.c index 9e836bef..cc28b35e 100644 --- a/doc-list.c +++ b/doc-list.c @@ -180,9 +180,10 @@ DEF_CMD(list_new) alloc(l, pane); INIT_LIST_HEAD(&l->content); p = doc_register(ci->home, &list_handle.c, l); - if (p) - return comm_call(ci->comm2, "callback:doc", p); - return Efail; + if (!p) + return Efail; + + return comm_call(ci->comm2, "callback:doc", p); } static void list_init_map(void) diff --git a/doc-multipart.c b/doc-multipart.c index 39eeb184..04043478 100644 --- a/doc-multipart.c +++ b/doc-multipart.c @@ -880,14 +880,14 @@ DEF_CMD(attach_mp) alloc(mpi, pane); h = doc_register(ci->home, &mp_handle.c, mpi); - if (h) { - mpi->doc.refcnt = mp_mark_refcnt; - attr_set_str(&h->attrs, "render-default", "text"); - return comm_call(ci->comm2, "callback:doc", h); + if (!h) { + unalloc(mpi, pane); + return Efail; } - free(mpi); - return Efail; + mpi->doc.refcnt = mp_mark_refcnt; + attr_set_str(&h->attrs, "render-default", "text"); + return comm_call(ci->comm2, "callback:doc", h); } void edlib_init(struct pane *ed safe) diff --git a/doc-text.c b/doc-text.c index 1af2e339..26992502 100644 --- a/doc-text.c +++ b/doc-text.c @@ -1818,9 +1818,10 @@ DEF_CMD(text_new) t->as.last_change = 0; text_new_alloc(t, 0); p = doc_register(ci->home, &text_handle.c, t); - if (p) - return comm_call(ci->comm2, "callback:doc", p); - return Efail; + if (!p) + return Efail; + + return comm_call(ci->comm2, "callback:doc", p); } DEF_CMD(text_new2) diff --git a/emacs-search.c b/emacs-search.c index ba978469..02dcb977 100644 --- a/emacs-search.c +++ b/emacs-search.c @@ -711,15 +711,17 @@ DEF_CMD(emacs_search) esi->backwards = ci->num & 1; p = pane_register(ci->focus, 0, &search_handle.c, esi); - if (p) { - call("doc:request:doc:replaced", p); - attr_set_str(&p->attrs, "status-line", " Search: case insensitive "); - comm_call(ci->comm2, "callback:attach", p); - pane_add_notify(p, esi->target, "Notify:Close"); + if (!p) + return Efail; + + call("doc:request:doc:replaced", p); + attr_set_str(&p->attrs, "status-line", " Search: case insensitive "); + comm_call(ci->comm2, "callback:attach", p); + pane_add_notify(p, esi->target, "Notify:Close"); + + if (ci->num & 2) + call("K:A-%", p); - if (ci->num & 2) - call("K:A-%", p); - } return 1; } @@ -1224,11 +1226,13 @@ DEF_CMD(emacs_search_attach_highlight) alloc(hi, pane); p = pane_register(ci->focus, 0, &highlight_handle.c, hi); - if (p) { - hi->view = home_call(ci->focus, "doc:add-view", p) - 1; - hi->replace_view = home_call(ci->focus, "doc:add-view", p) - 1; - comm_call(ci->comm2, "callback:attach", p); - } + if (!p) + return Efail; + + hi->view = home_call(ci->focus, "doc:add-view", p) - 1; + hi->replace_view = home_call(ci->focus, "doc:add-view", p) - 1; + comm_call(ci->comm2, "callback:attach", p); + return 1; } diff --git a/lang-python.c b/lang-python.c index fe309fb6..93236f8a 100644 --- a/lang-python.c +++ b/lang-python.c @@ -745,8 +745,10 @@ static int Pane_init(Pane *self safe, PyObject *args, PyObject *kwds) */ Py_INCREF(self); self->pane = pane_register(parent->pane, z, &self->cmd, self); - if (self->pane) - pane_get(self->pane); + if (!self->pane) + return -1; + + pane_get(self->pane); return 0; } diff --git a/lib-aspell.c b/lib-aspell.c index 2be4e3db..8fb4f4b0 100644 --- a/lib-aspell.c +++ b/lib-aspell.c @@ -57,13 +57,15 @@ DEF_CMD(aspell_attach_helper) alloc(as, pane); as->speller = safe_cast to_aspell_speller(ret); p = pane_register(ci->focus, 0, &aspell_handle.c, as); - if (p) { - call("doc:request:aspell:check", p); - call("doc:request:aspell:suggest", p); - call("doc:request:aspell:set-dict", p); - call("doc:request:aspell:add-word", p); - call("doc:request:aspell:save", p); - } + if (!p) + return Efail; + + call("doc:request:aspell:check", p); + call("doc:request:aspell:suggest", p); + call("doc:request:aspell:set-dict", p); + call("doc:request:aspell:add-word", p); + call("doc:request:aspell:save", p); + return 1; } diff --git a/lib-autosave.c b/lib-autosave.c index eaef0a9e..c02a9789 100644 --- a/lib-autosave.c +++ b/lib-autosave.c @@ -236,13 +236,14 @@ DEF_CMD(ask_autosave) p2 = NULL; if (p2) p2 = pane_register(p2, 0, &autosave_handle.c); - if (p2) { - attr_set_str(&p2->attrs, "orig_name", f); - attr_set_str(&p2->attrs, "autosave_name", a); - attr_set_str(&p2->attrs, "autosave_type", autosave_type); - if (doc) - pane_add_notify(p2, doc, "doc:replaced"); - } + if (!p2) + return Efail; + + attr_set_str(&p2->attrs, "orig_name", f); + attr_set_str(&p2->attrs, "autosave_name", a); + attr_set_str(&p2->attrs, "autosave_type", autosave_type); + if (doc) + pane_add_notify(p2, doc, "doc:replaced"); return 1; } diff --git a/lib-input.c b/lib-input.c index 3ccbce3d..f7707cf1 100644 --- a/lib-input.c +++ b/lib-input.c @@ -482,9 +482,10 @@ DEF_CMD(input_attach) im->num2 = 0; p = pane_register(ci->focus, 0, &input_handle.c, im); - if (p) - return comm_call(ci->comm2, "callback:attach", p); - return Efail; + if (!p) + return Efail; + + return comm_call(ci->comm2, "callback:attach", p); } void edlib_init(struct pane *ed safe) diff --git a/mode-emacs.c b/mode-emacs.c index 65575eda..cac83d70 100644 --- a/mode-emacs.c +++ b/mode-emacs.c @@ -1800,7 +1800,9 @@ DEF_CMD(emacs_shell) 0, NULL, "popup:close"); if (p) p = pane_register(p, 0, &find_handle.c, "shellcmd"); - if (p && ci->comm2) + if (!p) + return Efail; + if (ci->comm2) comm_call(ci->comm2, "cb", p); return 1; } diff --git a/render-format.c b/render-format.c index c2028af9..2fde945c 100644 --- a/render-format.c +++ b/render-format.c @@ -986,7 +986,9 @@ static struct pane *do_render_format_attach(struct pane *parent safe) alloc(rf, pane); p = pane_register(parent, 0, &render_format2_handle.c, rf); - if (p && !pane_attr_get(parent, "format:no-linecount")) { + if (!p) + return p; + if (!pane_attr_get(parent, "format:no-linecount")) { struct pane *p2 = call_ret(pane, "attach-line-count", p); if (p2) p = p2;