]> git.eshelyaron.com Git - emacs.git/commitdiff
* src/androidvfs.c (android_scan_directory_tree): Get rid of xstrdup.
authorPo Lu <luangruo@yahoo.com>
Fri, 16 Feb 2024 14:17:01 +0000 (22:17 +0800)
committerEshel Yaron <me@eshelyaron.com>
Sat, 17 Feb 2024 13:02:18 +0000 (14:02 +0100)
(cherry picked from commit 4b89fb08bdd7d0249698bc0ed578555d6755724d)

src/androidvfs.c

index 78f6b6da6a86d6ededb8a584db31b5ca184778a4..3030bd56cdc3d988584cef681c5ee17b00fa345b 100644 (file)
@@ -1018,8 +1018,8 @@ android_extract_long (char *pointer)
 static const char *
 android_scan_directory_tree (char *file, size_t *limit_return)
 {
-  char *token, *saveptr, *copy, *copy1, *start, *max, *limit;
-  size_t token_length, ntokens, i;
+  char *token, *saveptr, *copy, *start, *max, *limit;
+  size_t token_length, ntokens, i, len;
   char *tokens[10];
 
   USE_SAFE_ALLOCA;
@@ -1031,11 +1031,14 @@ android_scan_directory_tree (char *file, size_t *limit_return)
   limit = (char *) directory_tree + directory_tree_size;
 
   /* Now, split `file' into tokens, with the delimiter being the file
-     name separator.  Look for the file and seek past it.  */
+     name separator.  Look for the file and seek past it.  Create a copy
+     of FILE for the enjoyment of `strtok_r'.  */
 
   ntokens = 0;
   saveptr = NULL;
-  copy = copy1 = xstrdup (file);
+  len = strlen (file) + 1;
+  copy = SAFE_ALLOCA (len);
+  memcpy (copy, file, len);
   memset (tokens, 0, sizeof tokens);
 
   while ((token = strtok_r (copy, "/", &saveptr)))
@@ -1044,19 +1047,14 @@ android_scan_directory_tree (char *file, size_t *limit_return)
 
       /* Make sure ntokens is within bounds.  */
       if (ntokens == ARRAYELTS (tokens))
-       {
-         xfree (copy1);
-         goto fail;
-       }
+       goto fail;
 
-      tokens[ntokens] = SAFE_ALLOCA (strlen (token) + 1);
-      memcpy (tokens[ntokens], token, strlen (token) + 1);
+      len = strlen (token) + 1;
+      tokens[ntokens] = SAFE_ALLOCA (len);
+      memcpy (tokens[ntokens], token, len);
       ntokens++;
     }
 
-  /* Free the copy created for strtok_r.  */
-  xfree (copy1);
-
   /* If there are no tokens, just return the start of the directory
      tree.  */