]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - progs/toe.c
ncurses 5.9 - patch 20110514
[ncurses.git] / progs / toe.c
index 855fb2955cd648e57f6793b90b80382dc8692ba9..3203b5bd4833b8635e2225c693b2c67c53168502 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2011 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.50 2008/08/03 17:12:05 tom Exp $")
+MODULE_ID("$Id: toe.c,v 1.53 2011/05/14 22:35:49 tom Exp $")
 
 #define isDotname(name) (!strcmp(name, ".") || !strcmp(name, ".."))
 
@@ -61,6 +61,13 @@ ExitProgram(int code)
 }
 #endif
 
+static void
+failed(const char *msg)
+{
+    perror(msg);
+    ExitProgram(EXIT_FAILURE);
+}
+
 #if USE_HASHED_DB
 static bool
 make_db_name(char *dst, const char *src, unsigned limit)
@@ -184,10 +191,10 @@ typelist(int eargc, char *eargv[],
                DIRENT *entry;
 
                cwd_buf = typeRealloc(char, cwd_len, cwd_buf);
-               if (cwd_buf == 0) {
-                   perror("realloc cwd_buf");
-                   continue;
-               }
+               if (cwd_buf == 0)
+                   failed("realloc cwd_buf");
+
+               assert(cwd_buf != 0);
 
                strncpy(name_1, subdir->d_name, len)[len] = '\0';
                if (isDotname(name_1))
@@ -330,10 +337,10 @@ main(int argc, char *argv[])
     bool invert_dependencies = FALSE;
     bool header = FALSE;
     char *report_file = 0;
-    int i;
+    unsigned i;
     int code;
     int this_opt, last_opt = '?';
-    int v_opt = 0;
+    unsigned v_opt = 0;
 
     _nc_progname = _nc_rootname(argv[0]);
 
@@ -342,14 +349,14 @@ main(int argc, char *argv[])
        if (isdigit(this_opt)) {
            switch (last_opt) {
            case 'v':
-               v_opt = (this_opt - '0');
+               v_opt = (unsigned) (this_opt - '0');
                break;
            default:
                if (isdigit(last_opt))
                    v_opt *= 10;
                else
                    v_opt = 0;
-               v_opt += (this_opt - '0');
+               v_opt += (unsigned) (this_opt - '0');
                last_opt = this_opt;
            }
            continue;
@@ -399,7 +406,7 @@ main(int argc, char *argv[])
 
        for_entry_list(qp) {
            if (qp->nuses) {
-               int j;
+               unsigned j;
 
                (void) printf("%s:", _nc_first_name(qp->tterm.term_names));
                for (j = 0; j < qp->nuses; j++)
@@ -480,6 +487,10 @@ main(int argc, char *argv[])
            }
            if (!pass) {
                eargv = typeCalloc(char *, count + 1);
+               if (eargv == 0)
+                   failed("realloc eargv");
+
+               assert(eargv != 0);
            } else {
                code = typelist((int) count, eargv, header, deschook);
                while (count-- > 0)