]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/captoinfo.c
ncurses 6.0 - patch 20150912
[ncurses.git] / ncurses / tinfo / captoinfo.c
index cc57db31290ebb998a66705fb992c3b6df698abe..e02e622b0de3ee94ec710d9f08df26708656f6ce 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2012 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.70 2011/10/22 14:59:34 tom Exp $")
+MODULE_ID("$Id: captoinfo.c,v 1.77 2012/12/30 00:50:40 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;
@@ -133,7 +131,7 @@ save_string(char *d, const char *const s)
            _nc_err_abort(MSG_NO_MEMORY);
        d = my_string + have;
     }
-    (void) strcpy(d, s);
+    _nc_STRCPY(d, s, my_length - have);
     return d + strlen(d);
 }
 
@@ -515,7 +513,7 @@ bcd_expression(const char *str)
        {
            char buffer[80];
            int tst;
-           sprintf(buffer, fmt, ch1, ch2);
+           _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) fmt, ch1, ch2);
            tst = strlen(buffer) - 1;
            assert(len == tst);
        }
@@ -534,10 +532,13 @@ save_tc_char(char *bufptr, int c1)
            bufptr = save_char(bufptr, '\\');
        bufptr = save_char(bufptr, c1);
     } else {
-       if (c1 == (c1 & 0x1f))  /* iscntrl() returns T on 255 */
-           (void) strcpy(temp, unctrl((chtype) c1));
-       else
-           (void) sprintf(temp, "\\%03o", c1);
+       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;
@@ -680,7 +681,8 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz
                            break;
                        default:
                            /* should not happen, but handle this anyway */
-                           sprintf(octal, "%03o", UChar(xx1));
+                           _nc_SPRINTF(octal, _nc_SLIMIT(sizeof(octal))
+                                       "%03o", UChar(xx1));
                            bufptr = save_char(bufptr, octal[0]);
                            bufptr = save_char(bufptr, octal[1]);
                            xx1 = octal[2];
@@ -705,7 +707,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");
@@ -847,7 +850,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) */