OSDN Git Service

* src/lharc.c: use xstrdup() instead of strdup().
authorarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Sat, 18 May 2002 15:52:35 +0000 (15:52 +0000)
committerarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Sat, 18 May 2002 15:52:35 +0000 (15:52 +0000)
* src/lha_macro.h: ditto.

git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lha/lha/trunk@49 6a8cc165-1e22-0410-a132-eb4e3f353aba

src/lha_macro.h
src/lharc.c

index e00a8b1..27518de 100644 (file)
@@ -66,6 +66,7 @@ extern char    *getenv();
 
 extern char    *xmalloc();
 extern char    *xrealloc();
+extern char    *xstrdup();
 
 /* external variables */
 extern int      errno;
index 65c2612..1693344 100644 (file)
@@ -199,8 +199,7 @@ main(argc, argv)
        ac = argc;
        av = (char **)xmalloc( sizeof(char*)*argc );
        for (i=0; i<argc; i++) {
-         if ((av[i] = strdup( argv[i] )) == NULL)
-               fatal_error("not enough memory\n");
+        av[i] = xstrdup( argv[i] );
        }
 
        if (ac < 2)
@@ -414,8 +413,7 @@ work:
                        }
                        if (strlen(inpbuf) < 1)
                                continue;
-                       if ((xfilev[cmd_filec++] = (char *) strdup(inpbuf)) == NULL)
-                               fatal_error("Virtual memory exhausted\n");
+                       xfilev[cmd_filec++] = xstrdup(inpbuf);
                }
                xfilev[cmd_filec] = NULL;
                cmd_filev = xfilev;
@@ -616,6 +614,18 @@ xrealloc(old, size)
        return p;
 }
 
+char *
+xstrdup(str)
+       char *str;
+{
+    int len = strlen(str);
+       char *p = (char *)xmalloc(str + 1);
+       if (!p)
+               fatal_error("Not enough memory");
+    strcpy(p, str);
+       return p;
+}
+
 /* ------------------------------------------------------------------------ */
 /*                                                             STRING POOL                                                                     */
 /* ------------------------------------------------------------------------ */