aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2024-02-16 22:17:01 +0800
committerPo Lu2024-02-16 22:17:57 +0800
commit4b89fb08bdd7d0249698bc0ed578555d6755724d (patch)
tree96fd702f152859c59112149ab248535cf1512373 /src
parent44a1721156ec29e5799da94f7918f217f52fd751 (diff)
downloademacs-4b89fb08bdd7d0249698bc0ed578555d6755724d.tar.gz
emacs-4b89fb08bdd7d0249698bc0ed578555d6755724d.zip
* src/androidvfs.c (android_scan_directory_tree): Get rid of xstrdup.
Diffstat (limited to 'src')
-rw-r--r--src/androidvfs.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/androidvfs.c b/src/androidvfs.c
index 78f6b6da6a8..3030bd56cdc 100644
--- a/src/androidvfs.c
+++ b/src/androidvfs.c
@@ -1018,8 +1018,8 @@ android_extract_long (char *pointer)
1018static const char * 1018static const char *
1019android_scan_directory_tree (char *file, size_t *limit_return) 1019android_scan_directory_tree (char *file, size_t *limit_return)
1020{ 1020{
1021 char *token, *saveptr, *copy, *copy1, *start, *max, *limit; 1021 char *token, *saveptr, *copy, *start, *max, *limit;
1022 size_t token_length, ntokens, i; 1022 size_t token_length, ntokens, i, len;
1023 char *tokens[10]; 1023 char *tokens[10];
1024 1024
1025 USE_SAFE_ALLOCA; 1025 USE_SAFE_ALLOCA;
@@ -1031,11 +1031,14 @@ android_scan_directory_tree (char *file, size_t *limit_return)
1031 limit = (char *) directory_tree + directory_tree_size; 1031 limit = (char *) directory_tree + directory_tree_size;
1032 1032
1033 /* Now, split `file' into tokens, with the delimiter being the file 1033 /* Now, split `file' into tokens, with the delimiter being the file
1034 name separator. Look for the file and seek past it. */ 1034 name separator. Look for the file and seek past it. Create a copy
1035 of FILE for the enjoyment of `strtok_r'. */
1035 1036
1036 ntokens = 0; 1037 ntokens = 0;
1037 saveptr = NULL; 1038 saveptr = NULL;
1038 copy = copy1 = xstrdup (file); 1039 len = strlen (file) + 1;
1040 copy = SAFE_ALLOCA (len);
1041 memcpy (copy, file, len);
1039 memset (tokens, 0, sizeof tokens); 1042 memset (tokens, 0, sizeof tokens);
1040 1043
1041 while ((token = strtok_r (copy, "/", &saveptr))) 1044 while ((token = strtok_r (copy, "/", &saveptr)))
@@ -1044,19 +1047,14 @@ android_scan_directory_tree (char *file, size_t *limit_return)
1044 1047
1045 /* Make sure ntokens is within bounds. */ 1048 /* Make sure ntokens is within bounds. */
1046 if (ntokens == ARRAYELTS (tokens)) 1049 if (ntokens == ARRAYELTS (tokens))
1047 { 1050 goto fail;
1048 xfree (copy1);
1049 goto fail;
1050 }
1051 1051
1052 tokens[ntokens] = SAFE_ALLOCA (strlen (token) + 1); 1052 len = strlen (token) + 1;
1053 memcpy (tokens[ntokens], token, strlen (token) + 1); 1053 tokens[ntokens] = SAFE_ALLOCA (len);
1054 memcpy (tokens[ntokens], token, len);
1054 ntokens++; 1055 ntokens++;
1055 } 1056 }
1056 1057
1057 /* Free the copy created for strtok_r. */
1058 xfree (copy1);
1059
1060 /* If there are no tokens, just return the start of the directory 1058 /* If there are no tokens, just return the start of the directory
1061 tree. */ 1059 tree. */
1062 1060