]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/captoinfo.c
ncurses 6.0 - patch 20170318
[ncurses.git] / ncurses / tinfo / captoinfo.c
index 80ee6a334f7f46fe1af096d1dea8aed0f82b35e1..4959edc72a1efde65303afb716088963149aca19 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -93,7 +93,7 @@
 #include <ctype.h>
 #include <tic.h>
 
-MODULE_ID("$Id: captoinfo.c,v 1.72 2012/02/22 22:40:24 tom Exp $")
+MODULE_ID("$Id: captoinfo.c,v 1.79 2017/02/11 20:08:49 tom Exp $")
 
 #define MAX_PUSHED     16      /* max # args we can push onto the stack */
 
@@ -114,9 +114,7 @@ init_string(void)
 /* initialize 'my_string', 'my_length' */
 {
     if (my_string == 0)
-       my_string = typeMalloc(char, my_length = 256);
-    if (my_string == 0)
-       _nc_err_abort(MSG_NO_MEMORY);
+       TYPE_MALLOC(char, my_length = 256, my_string);
 
     *my_string = '\0';
     return my_string;
@@ -241,7 +239,7 @@ getparm(int parm, int n)
            parm = 1;
     }
 
-    while (n--) {
+    while (n-- > 0) {
        dp = save_string(dp, "%p");
        dp = save_char(dp, '0' + parm);
     }
@@ -250,7 +248,7 @@ getparm(int parm, int n)
        if (n > 1) {
            _nc_warning("string may not be optimal");
            dp = save_string(dp, "%Pa");
-           while (n--) {
+           while (n-- > 0) {
                dp = save_string(dp, "%ga");
            }
        }
@@ -527,17 +525,20 @@ bcd_expression(const char *str)
 static char *
 save_tc_char(char *bufptr, int c1)
 {
-    char temp[80];
-
     if (is7bits(c1) && isprint(c1)) {
        if (c1 == ':' || c1 == '\\')
            bufptr = save_char(bufptr, '\\');
        bufptr = save_char(bufptr, c1);
     } else {
-       if (c1 == (c1 & 0x1f))  /* iscntrl() returns T on 255 */
-           _nc_STRCPY(temp, unctrl((chtype) c1), sizeof(temp));
-       else
-           _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) "\\%03o", c1);
+       char temp[80];
+
+       if (c1 == (c1 & 0x1f)) {        /* iscntrl() returns T on 255 */
+           _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+                       "%.20s", unctrl((chtype) c1));
+       } else {
+           _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+                       "\\%03o", c1);
+       }
        bufptr = save_string(bufptr, temp);
     }
     return bufptr;
@@ -624,13 +625,15 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz
            } else if (str[1] == ',') {
                bufptr = save_char(bufptr, *++str);
            } else {
-               int xx1, xx2;
+               int xx1;
 
                bufptr = save_char(bufptr, *str++);
                xx1 = *str;
                if (_nc_strict_bsd) {
+
                    if (isdigit(UChar(xx1))) {
                        int pad = 0;
+                       int xx2;
 
                        if (!isdigit(UChar(str[1])))
                            pad = 2;
@@ -706,7 +709,8 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz
                   && ((in0 == 4 && in1 == 10 && in2 == 48)
                       || (in0 == 3 && in1 == 9 && in2 == 38))) {
            /* dumb-down an optimized case from xterm-256color for termcap */
-           str = strstr(str, ";m");
+           if ((str = strstr(str, ";m")) == 0)
+               break;          /* cannot happen */
            ++str;
            if (in2 == 48) {
                bufptr = save_string(bufptr, "[48;5;%dm");
@@ -848,7 +852,7 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz
         * but that may not be the end of the string.
         */
        assert(str != 0);
-       if (*str == '\0')
+       if (str == 0 || *str == '\0')
            break;
 
     }                          /* endwhile (*str) */