]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
wordsplit_get_words need not fail
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 3 Aug 2024 22:45:53 +0000 (15:45 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 4 Aug 2024 08:41:43 +0000 (01:41 -0700)
* lib/wordsplit.c (wordsplit_get_words):
Do not fail merely because realloc fails.
Return void, since failure is no longer possible.

lib/wordsplit.c
lib/wordsplit.h

index d6b33af8703d6d0a498e76a6ae8253ebd74ddeb5..48243f21b43cc183761ea293d37ae7a7ce018017 100644 (file)
@@ -2524,22 +2524,18 @@ wordsplit_free (struct wordsplit *ws)
   wordsplit_free_envbuf (ws);
 }
 
-int
+void
 wordsplit_get_words (struct wordsplit *ws, idx_t *wordc, char ***wordv)
 {
   /* Tell the memory manager that ws->ws_wordv can be shrunk.  */
   char **p = realloc (ws->ws_wordv,
                      (ws->ws_wordc + 1) * sizeof (ws->ws_wordv[0]));
-  if (!p)
-    return -1;
-  *wordv = p;
+  *wordv = p ? p : ws->ws_wordv;
   *wordc = ws->ws_wordc;
 
   ws->ws_wordv = NULL;
   ws->ws_wordc = 0;
   ws->ws_wordn = 0;
-
-  return 0;
 }
 
 static char const *const wordsplit_errstr[] = {
index 4640d34c063e413c64947352ec9fcdec41c785d0..b10c7b82f48c789e993504ddc71e10cd89837ae6 100644 (file)
@@ -249,7 +249,7 @@ int wordsplit_len (const char *s, idx_t len, wordsplit_t *ws, unsigned flags);
 void wordsplit_free (wordsplit_t *ws);
 void wordsplit_free_words (wordsplit_t *ws);
 void wordsplit_free_envbuf (wordsplit_t *ws);
-int wordsplit_get_words (wordsplit_t *ws, idx_t *wordc, char ***wordv);
+void wordsplit_get_words (wordsplit_t *ws, idx_t *wordc, char ***wordv);
 
 int wordsplit_append (wordsplit_t *wsp, int argc, char **argv);