From 3c94ec04f2bfa3f0e604d13a93be588ddb606b8e Mon Sep 17 00:00:00 2001 From: roy Date: Mon, 30 Jan 2017 17:15:52 +0000 Subject: [PATCH] Just return ERR instead of asserting if someone calls the slk routines to affect the ripped off window before the window is actually ripped off. --- lib/libcurses/slk.c | 51 +++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/lib/libcurses/slk.c b/lib/libcurses/slk.c index d3b98f5cc6c9..eccc2a0c1693 100644 --- a/lib/libcurses/slk.c +++ b/lib/libcurses/slk.c @@ -1,4 +1,4 @@ -/* $NetBSD: slk.c,v 1.1 2017/01/24 17:27:30 roy Exp $ */ +/* $NetBSD: slk.c,v 1.2 2017/01/30 17:15:52 roy Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -31,10 +31,9 @@ #include #ifndef lint -__RCSID("$NetBSD: slk.c,v 1.1 2017/01/24 17:27:30 roy Exp $"); +__RCSID("$NetBSD: slk.c,v 1.2 2017/01/30 17:15:52 roy Exp $"); #endif /* not lint */ -#include #include #include #include @@ -280,8 +279,7 @@ static int __slk_attron(SCREEN *screen, const chtype attr) { - assert(screen != NULL); - if (screen->slk_window == NULL) + if (screen == NULL || screen->slk_window == NULL) return ERR; return wattron(screen->slk_window, attr); } @@ -294,8 +292,7 @@ static int __slk_attr_on(SCREEN *screen, const attr_t attr, void *opt) { - assert(screen != NULL); - if (screen->slk_window == NULL) + if (screen == NULL || screen->slk_window == NULL) return ERR; return wattr_on(screen->slk_window, attr, opt); } @@ -308,8 +305,7 @@ static int __slk_attroff(SCREEN *screen, const chtype attr) { - assert(screen != NULL); - if (screen->slk_window == NULL) + if (screen == NULL || screen->slk_window == NULL) return ERR; return wattroff(screen->slk_window, attr); } @@ -322,8 +318,7 @@ static int __slk_attr_off(SCREEN *screen, const attr_t attr, void *opt) { - assert(screen != NULL); - if (screen->slk_window == NULL) + if (screen == NULL || screen->slk_window == NULL) return ERR; return wattr_off(screen->slk_window, attr, opt); } @@ -336,8 +331,7 @@ static int __slk_attrset(SCREEN *screen, const chtype attr) { - assert(screen != NULL); - if (screen->slk_window == NULL) + if (screen == NULL || screen->slk_window == NULL) return ERR; return wattrset(screen->slk_window, attr); } @@ -350,8 +344,7 @@ static int __slk_attr_set(SCREEN *screen, const attr_t attr, short pair, void *opt) { - assert(screen != NULL); - if (screen->slk_window == NULL) + if (screen == NULL || screen->slk_window == NULL) return ERR; return wattr_set(screen->slk_window, attr, pair, opt); } @@ -364,7 +357,8 @@ static int __slk_clear(SCREEN *screen) { - assert(screen != NULL); + if (screen == NULL) + return ERR; screen->slk_hidden = true; if (screen->is_term_slk) { if (t_label_off(screen->term) == NULL) @@ -386,8 +380,7 @@ static int __slk_color(SCREEN *screen, short pair) { - assert(screen != NULL); - if (screen->slk_window == NULL) + if (screen == NULL || screen->slk_window == NULL) return ERR; return wcolor_set(screen->slk_window, pair, NULL); } @@ -401,8 +394,7 @@ static char * __slk_label(SCREEN *screen, int labnum) { - assert(screen != NULL); - if (labnum < 1 || labnum > screen->slk_nlabels) + if (screen == NULL || labnum < 1 || labnum > screen->slk_nlabels) return NULL; return screen->slk_labels[--labnum].text; } @@ -415,8 +407,7 @@ int __slk_noutrefresh(SCREEN *screen) { - assert(screen != NULL); - if (screen->slk_window == NULL) + if (screen == NULL || screen->slk_window == NULL) return ERR; return wnoutrefresh(screen->slk_window); } @@ -429,7 +420,8 @@ static int __slk_restore(SCREEN *screen) { - assert(screen != NULL); + if (screen == NULL) + return ERR; screen->slk_hidden = false; if (screen->is_term_slk) { if (t_label_on(screen->term) == NULL) @@ -461,9 +453,8 @@ __slk_set(SCREEN *screen, int labnum, const char *label, int justify) size_t wc_len; #endif - assert(screen != NULL); /* Check args. */ - if (labnum < 1 || labnum > screen->slk_nlabels) + if (screen == NULL || labnum < 1 || labnum > screen->slk_nlabels) return ERR; switch(justify) { case SLK_JUSTIFY_LEFT: @@ -520,8 +511,7 @@ static int __slk_touch(SCREEN *screen) { - assert(screen != NULL); - if (screen->slk_window == NULL) + if (screen == NULL || screen->slk_window == NULL) return ERR; return touchwin(screen->slk_window); } @@ -540,7 +530,8 @@ __slk_wset(SCREEN *screen, int labnum, const wchar_t *label, int justify) char *str; int result = ERR; - assert(screen != NULL); + if (screen == NULL) + return ERR; olabel = label; if ((len = wcsrtombs(NULL, &olabel, 0, &screen->sp)) == -1) return ERR; @@ -624,7 +615,6 @@ __slk_ripoffline(WINDOW *window, int cols) if (window == NULL) return ERR; - assert(window->screen->slk_window == NULL); window->screen->slk_window = window; wattron(window, (t_no_color_video(window->screen->term) & 1) == 0 @@ -643,7 +633,8 @@ __slk_resize(SCREEN *screen, int cols) int x = 0; struct __slk_label *l; - assert(screen != NULL); + if (screen == NULL) + return ERR; if (screen->is_term_slk || screen->slk_nlabels == 0) return OK;