Pass errret pointer to setupterm() to prevent setupterm()
authormillert <millert@openbsd.org>
Fri, 8 Jul 2016 15:23:44 +0000 (15:23 +0000)
committermillert <millert@openbsd.org>
Fri, 8 Jul 2016 15:23:44 +0000 (15:23 +0000)
from calling exit() when given an unknown terminal type.
From Anton Lindqvist, who also upstreamed the fix.

usr.bin/less/screen.c

index 5063250..a794afc 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <sys/ioctl.h>
 
+#include <err.h>
 #include <term.h>
 #include <termios.h>
 
@@ -266,6 +267,7 @@ get_term(void)
 {
        char *t1, *t2;
        char *term;
+       int  err;
 
        /*
         * Find out what kind of terminal this is.
@@ -274,8 +276,11 @@ get_term(void)
                term = DEFAULT_TERM;
        hardcopy = 0;
 
-       if (setupterm(term, 1, NULL) < 0) {
-               hardcopy = 1;
+       if (setupterm(term, 1, &err) < 0) {
+               if (err == 1)
+                       hardcopy = 1;
+               else
+                       errx(1, "%s: unknown terminal type", term);
        }
        if (hard_copy == 1)
                hardcopy = 1;