]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - progs/toe.c
ncurses 5.9 - patch 20150321
[ncurses.git] / progs / toe.c
index 4924d2c1cccf32da6266f958d49c028aae7965a8..0d299b457dfb9d61c555cef71897f8f04325a076 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 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            *
@@ -44,7 +44,7 @@
 #include <hashed_db.h>
 #endif
 
-MODULE_ID("$Id: toe.c,v 1.68 2012/07/21 22:55:59 tom Exp $")
+MODULE_ID("$Id: toe.c,v 1.74 2013/12/15 01:08:28 tom Exp $")
 
 #define isDotname(name) (!strcmp(name, ".") || !strcmp(name, ".."))
 
@@ -99,6 +99,8 @@ new_termdata(void)
     if (want >= len_termdata) {
        len_termdata = (2 * want) + 10;
        ptr_termdata = typeRealloc(TERMDATA, len_termdata, ptr_termdata);
+       if (ptr_termdata == 0)
+           failed("ptr_termdata");
     }
 
     return ptr_termdata + use_termdata++;
@@ -230,9 +232,9 @@ make_db_name(char *dst, const char *src, unsigned limit)
     static const char suffix[] = DBM_SUFFIX;
 
     bool result = FALSE;
-    unsigned lens = sizeof(suffix) - 1;
-    unsigned size = strlen(src);
-    unsigned need = lens + size;
+    size_t lens = sizeof(suffix) - 1;
+    size_t size = strlen(src);
+    size_t need = lens + size;
 
     if (need <= limit) {
        if (size >= lens
@@ -257,8 +259,11 @@ term_description(TERMTYPE *tp)
 {
     const char *desc;
 
-    if ((desc = strrchr(tp->term_names, '|')) == 0 || *++desc == '\0')
+    if (tp->term_names == 0
+       || (desc = strrchr(tp->term_names, '|')) == 0
+       || (*++desc == '\0')) {
        desc = "(No description)";
+    }
 
     return desc;
 }
@@ -318,7 +323,7 @@ sorthook(int db_index, int db_limit, const char *term_name, TERMTYPE *tp)
     data->description = strmalloc(term_description(tp));
 }
 
-#if USE_TERMCAP
+#if NCURSES_USE_TERMCAP
 static void
 show_termcap(int db_index, int db_limit, char *buffer, DescHook hook)
 {
@@ -345,7 +350,7 @@ show_termcap(int db_index, int db_limit, char *buffer, DescHook hook)
 }
 #endif
 
-#if USE_DATABASE
+#if NCURSES_USE_DATABASE
 static char *
 copy_entryname(DIRENT * src)
 {
@@ -362,14 +367,14 @@ copy_entryname(DIRENT * src)
 
 static int
 typelist(int eargc, char *eargv[],
-        bool verbosity,
+        int verbosity,
         DescHook hook)
 /* apply a function to each entry in given terminfo directories */
 {
     int i;
 
     for (i = 0; i < eargc; i++) {
-#if USE_DATABASE
+#if NCURSES_USE_DATABASE
        if (_nc_is_dir_path(eargv[i])) {
            char *cwd_buf = 0;
            DIR *termdir;
@@ -435,7 +440,10 @@ typelist(int eargc, char *eargv[],
                        (void) fprintf(stderr,
                                       "%s: couldn't open terminfo file %s.\n",
                                       _nc_progname, name_2);
+                       free(cwd_buf);
                        free(name_2);
+                       closedir(entrydir);
+                       closedir(termdir);
                        return (EXIT_FAILURE);
                    }
 
@@ -494,7 +502,7 @@ typelist(int eargc, char *eargv[],
        }
 #endif
 #endif
-#if USE_TERMCAP
+#if NCURSES_USE_TERMCAP
 #if HAVE_BSD_CGETENT
        {
            CGETENT_CONST char *db_array[2];
@@ -702,6 +710,8 @@ main(int argc, char *argv[])
            }
            if (!pass) {
                eargv = allocArgv(count);
+               if (eargv == 0)
+                   failed("eargv");
            } else {
                code = typelist((int) count, eargv, header, hook);
                freeArgv(eargv);
@@ -711,9 +721,11 @@ main(int argc, char *argv[])
        DBDIRS state;
        int offset;
        const char *path;
-       char **eargv = allocArgv(2);
+       char **eargv = allocArgv((size_t) 2);
        size_t count = 0;
 
+       if (eargv == 0)
+           failed("eargv");
        _nc_first_db(&state, &offset);
        if ((path = _nc_next_db(&state, &offset)) != 0) {
            eargv[count++] = strmalloc(path);