]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Simplify read_incr_db_01 malloc
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 2 Nov 2024 18:52:28 +0000 (11:52 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 2 Nov 2024 20:43:05 +0000 (13:43 -0700)
* src/incremen.c (read_incr_db_01): Replace arg initbuf with two
args pbuf and pbufsize so that we can simplify memory allocation.
Caller changed.  Omit now-unnecessary free, xstrdup, strlen.

src/incremen.c

index 769eff3bd146c02d7fdc51e7d77d93e5c8a93f47..b97ff4f404f01391b9c50901b0e78e1b0ca36944 100644 (file)
@@ -1020,30 +1020,22 @@ enum { TAR_INCREMENTAL_VERSION = 2 };
 
 /* Read incremental snapshot formats 0 and 1 */
 static void
-read_incr_db_01 (bool version_1, const char *initbuf)
+read_incr_db_01 (bool version_1, char **pbuf, size_t *pbufsize)
 {
-  char *buf = NULL;
-  size_t bufsize = 0;
   char *ebuf;
   intmax_t lineno = 1;
 
   if (version_1)
     {
-      if (getline (&buf, &bufsize, listed_incremental_stream) <= 0)
+      if (getline (pbuf, pbufsize, listed_incremental_stream) <= 0)
        {
          read_error (listed_incremental_option);
-         free (buf);
          return;
        }
       ++lineno;
     }
-  else
-    {
-      buf = xstrdup (initbuf);
-      bufsize = strlen (buf) + 1;
-    }
 
-  newer_mtime_option = decode_timespec (buf, &ebuf, false);
+  newer_mtime_option = decode_timespec (*pbuf, &ebuf, false);
 
   if (! valid_timespec (newer_mtime_option))
     paxfatal (errno, "%s:%jd: %s",
@@ -1069,10 +1061,11 @@ read_incr_db_01 (bool version_1, const char *initbuf)
     }
 
   for (ssize_t n;
-       0 < (n = getline (&buf, &bufsize, listed_incremental_stream)); )
+       0 < (n = getline (pbuf, pbufsize, listed_incremental_stream)); )
     {
       dev_t dev;
       ino_t ino;
+      char *buf = *pbuf;
       bool nfs = buf[0] == '+';
       char *strp = buf + nfs;
       struct timespec mtime;
@@ -1125,7 +1118,6 @@ read_incr_db_01 (bool version_1, const char *initbuf)
       unquote_string (strp);
       note_directory (strp, mtime, dev, ino, nfs, false, NULL);
     }
-  free (buf);
 }
 
 /* Read a nul-terminated string from FP and store it in STK.
@@ -1411,7 +1403,7 @@ read_directory_file (void)
        {
        case 0:
        case 1:
-         read_incr_db_01 (incremental_version, buf);
+         read_incr_db_01 (incremental_version, &buf, &bufsize);
          break;
 
        case TAR_INCREMENTAL_VERSION: