]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix initscr() crash on NetBSD
authorsin <sin@2f30.org>
Thu, 10 Mar 2016 17:00:12 +0000 (17:00 +0000)
committersin <sin@2f30.org>
Thu, 10 Mar 2016 17:03:12 +0000 (17:03 +0000)
NetBSD has its own curses implementation and initscr() does not
terminate with an error if TERM is not set properly.

Instead check the return value and exit if an initialization
error occurs.

noice.c

diff --git a/noice.c b/noice.c
index 489caabe617b7c1cc25d26bdc3522de72971fff4..a588a55cede83b485cd0c2758cdca7b26cb275db 100644 (file)
--- a/noice.c
+++ b/noice.c
@@ -257,7 +257,16 @@ entrycmp(const void *va, const void *vb)
 void
 initcurses(void)
 {
-       initscr();
+       char *term;
+
+       if (initscr() == NULL) {
+               term = getenv("TERM");
+               if (term != NULL)
+                       fprintf(stderr, "error opening terminal: %s\n", term);
+               else
+                       fprintf(stderr, "failed to initialize curses\n");
+               exit(1);
+       }
        cbreak();
        noecho();
        nonl();