]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
tgetent may fail.
authorBruno Haible <bruno@clisp.org>
Mon, 18 Dec 2006 12:03:31 +0000 (12:03 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:14:30 +0000 (12:14 +0200)
gnulib-local/ChangeLog
gnulib-local/lib/term-ostream.oo.c

index 6a422585b3a7138f771c9a4275a0df30be4a995a..7456380d2957f60c6e76cb773c9a3f12a27407ff 100644 (file)
@@ -1,3 +1,8 @@
+2006-12-16  Bruno Haible  <bruno@clisp.org>
+
+       * lib/term-ostream.oo.c (term_ostream_create): Don't ignore tgetent's
+       return value.
+
 2006-12-16  Bruno Haible  <bruno@clisp.org>
 
        * lib/libcroco/cr-style.h (enum CRPositionType): Remove trailing
index 11918b03015cb0045784945ff22d5cfa6ac4269d..ed524db6221b864d9c70a570dea31c4cdb4ffda6 100644 (file)
@@ -1694,9 +1694,7 @@ term_ostream_create (int fd, const char *filename)
   if (term != NULL && term[0] != '\0')
     {
       struct { char buf[1024]; char canary[4]; } termcapbuf;
-      struct { char buf[1024]; char canary[4]; } termentrybuf;
       int retval;
-      char *termentryptr;
 
       /* Call tgetent, being defensive against buffer overflow.  */
       memcpy (termcapbuf.canary, "CnRy", 4);
@@ -1705,50 +1703,56 @@ term_ostream_create (int fd, const char *filename)
        /* Buffer overflow!  */
        abort ();
 
-      /* Prepare for calling tgetstr, being defensive against buffer
-        overflow.  ncurses' tgetstr() supports a second argument NULL,
-        but NetBSD's tgetstr() doesn't.  */
-      memcpy (termentrybuf.canary, "CnRz", 4);
-      #define TEBP ((termentryptr = termentrybuf.buf), &termentryptr)
-
-      /* Retrieve particular values depending on the terminal type.  */
-      stream->max_colors = tgetnum ("Co");
-      stream->no_color_video = tgetnum ("nc");
-      stream->set_a_foreground = xstrdup0 (tgetstr ("AF", TEBP));
-      stream->set_foreground = xstrdup0 (tgetstr ("Sf", TEBP));
-      stream->set_a_background = xstrdup0 (tgetstr ("AB", TEBP));
-      stream->set_background = xstrdup0 (tgetstr ("Sb", TEBP));
-      stream->orig_pair = xstrdup0 (tgetstr ("op", TEBP));
-      stream->enter_bold_mode = xstrdup0 (tgetstr ("md", TEBP));
-      stream->enter_italics_mode = xstrdup0 (tgetstr ("ZH", TEBP));
-      stream->exit_italics_mode = xstrdup0 (tgetstr ("ZR", TEBP));
-      stream->enter_underline_mode = xstrdup0 (tgetstr ("us", TEBP));
-      stream->exit_underline_mode = xstrdup0 (tgetstr ("ue", TEBP));
-      stream->exit_attribute_mode = xstrdup0 (tgetstr ("me", TEBP));
+      if (retval > 0)
+       {
+         struct { char buf[1024]; char canary[4]; } termentrybuf;
+         char *termentryptr;
+
+         /* Prepare for calling tgetstr, being defensive against buffer
+            overflow.  ncurses' tgetstr() supports a second argument NULL,
+            but NetBSD's tgetstr() doesn't.  */
+         memcpy (termentrybuf.canary, "CnRz", 4);
+         #define TEBP ((termentryptr = termentrybuf.buf), &termentryptr)
+
+         /* Retrieve particular values depending on the terminal type.  */
+         stream->max_colors = tgetnum ("Co");
+         stream->no_color_video = tgetnum ("nc");
+         stream->set_a_foreground = xstrdup0 (tgetstr ("AF", TEBP));
+         stream->set_foreground = xstrdup0 (tgetstr ("Sf", TEBP));
+         stream->set_a_background = xstrdup0 (tgetstr ("AB", TEBP));
+         stream->set_background = xstrdup0 (tgetstr ("Sb", TEBP));
+         stream->orig_pair = xstrdup0 (tgetstr ("op", TEBP));
+         stream->enter_bold_mode = xstrdup0 (tgetstr ("md", TEBP));
+         stream->enter_italics_mode = xstrdup0 (tgetstr ("ZH", TEBP));
+         stream->exit_italics_mode = xstrdup0 (tgetstr ("ZR", TEBP));
+         stream->enter_underline_mode = xstrdup0 (tgetstr ("us", TEBP));
+         stream->exit_underline_mode = xstrdup0 (tgetstr ("ue", TEBP));
+         stream->exit_attribute_mode = xstrdup0 (tgetstr ("me", TEBP));
 
 #ifdef __BEOS__
-      /* The BeOS termcap entry for "beterm" is broken: For "AF" and "AB" it
-        contains balues in terminfo syntax but the system's tparam() function
-        understands only the termcap syntax.  */
-      if (stream->set_a_foreground != NULL
-         && strcmp (stream->set_a_foreground, "\033[3%p1%dm") == 0)
-       {
-         free (stream->set_a_foreground);
-         stream->set_a_foreground = xstrdup ("\033[3%dm");
-       }
-      if (stream->set_a_background != NULL
-         && strcmp (stream->set_a_background, "\033[4%p1%dm") == 0)
-       {
-         free (stream->set_a_background);
-         stream->set_a_background = xstrdup ("\033[4%dm");
-       }
+         /* The BeOS termcap entry for "beterm" is broken: For "AF" and "AB"
+            it contains balues in terminfo syntax but the system's tparam()
+            function understands only the termcap syntax.  */
+         if (stream->set_a_foreground != NULL
+             && strcmp (stream->set_a_foreground, "\033[3%p1%dm") == 0)
+           {
+             free (stream->set_a_foreground);
+             stream->set_a_foreground = xstrdup ("\033[3%dm");
+           }
+         if (stream->set_a_background != NULL
+             && strcmp (stream->set_a_background, "\033[4%p1%dm") == 0)
+           {
+             free (stream->set_a_background);
+             stream->set_a_background = xstrdup ("\033[4%dm");
+           }
 #endif
 
-      /* Done with tgetstr.  Detect possible buffer overflow.  */
-      #undef TEBP
-      if (memcmp (termentrybuf.canary, "CnRz", 4) != 0)
-       /* Buffer overflow!  */
-       abort ();
+         /* Done with tgetstr.  Detect possible buffer overflow.  */
+         #undef TEBP
+         if (memcmp (termentrybuf.canary, "CnRz", 4) != 0)
+           /* Buffer overflow!  */
+           abort ();
+       }
     }
 
   /* Infer the capabilities.  */