bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 8/8] posix: Remove all alloca usage in glob


From: Adhemerval Zanella
Subject: [PATCH 8/8] posix: Remove all alloca usage in glob
Date: Tue, 5 Jan 2021 15:58:20 -0300

With alloca usage removal from glob this patch wraps it up by removing
all the alloca defines and macros usage.

Checked on x86_64-linux-gnu.
---
 posix/glob.c | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/posix/glob.c b/posix/glob.c
index b6727ee884..c7a89a5298 100644
--- a/posix/glob.c
+++ b/posix/glob.c
@@ -42,7 +42,6 @@
 
 #ifndef WINDOWS32
 # include <pwd.h>
-# include <alloca.h>
 #endif
 
 #include <errno.h>
@@ -74,7 +73,6 @@
 # define __fxstatat64(_, d, f, st, flag) fstatat (d, f, st, flag)
 # define struct_stat64          struct stat
 # ifndef __MVS__
-#  define __alloca              alloca
 # endif
 # define __readdir              readdir
 # define COMPILE_GLOB64
@@ -184,12 +182,6 @@ convert_dirent64 (const struct dirent64 *source)
 # ifdef GNULIB_defined_closedir
 #  undef closedir
 # endif
-
-/* Just use malloc.  */
-# define __libc_use_alloca(n) false
-# define alloca_account(len, avar) ((void) (len), (void) (avar), (void *) 0)
-# define extend_alloca_account(buf, len, newlen, avar) \
-    ((void) (buf), (void) (len), (void) (newlen), (void) (avar), (void *) 0)
 #endif
 
 static int
@@ -217,7 +209,7 @@ glob_lstat (glob_t *pglob, int flags, const char *fullname)
 
 static int glob_in_dir (const char *pattern, const char *directory,
                         int flags, int (*errfunc) (const char *, int),
-                        glob_t *pglob, size_t alloca_used);
+                        glob_t *pglob);
 static int prefix_array (const char *prefix, char **array, size_t n) __THROWNL;
 static int collated_compare (const void *, const void *) __THROWNL;
 
@@ -282,7 +274,6 @@ __glob (const char *pattern, int flags, int (*errfunc) 
(const char *, int),
   int meta;
   glob_t dirs;
   int retval = 0;
-  size_t alloca_used = 0;
   struct char_array dirname;
   bool dirname_modified;
 
@@ -530,11 +521,13 @@ __glob (const char *pattern, int flags, int (*errfunc) 
(const char *, int),
           char *drive_spec;
 
           ++dirlen;
-          drive_spec = __alloca (dirlen + 1);
+          drive_spec = malloca (dirlen + 1);
           *((char *) mempcpy (drive_spec, pattern, dirlen)) = '\0';
           /* For now, disallow wildcards in the drive spec, to
              prevent infinite recursion in glob.  */
-          if (__glob_pattern_p (drive_spec, !(flags & GLOB_NOESCAPE)))
+          int r = __glob_pattern_p (drive_spec, !(flags & GLOB_NOESCAPE));
+          free (drive_spec);
+          if (r != 0)
            {
              retval = GLOB_NOMATCH;
              goto out;
@@ -935,7 +928,7 @@ __glob (const char *pattern, int flags, int (*errfunc) 
(const char *, int),
           status = glob_in_dir (filename, dirs.gl_pathv[i],
                                 ((flags | GLOB_APPEND)
                                  & ~(GLOB_NOCHECK | GLOB_NOMAGIC)),
-                                errfunc, pglob, alloca_used);
+                                errfunc, pglob);
           if (status == GLOB_NOMATCH)
             /* No matches in this directory.  Try the next.  */
             continue;
@@ -1040,7 +1033,7 @@ __glob (const char *pattern, int flags, int (*errfunc) 
(const char *, int),
       if (dirname_modified)
         flags &= ~(GLOB_NOCHECK | GLOB_NOMAGIC);
       status = glob_in_dir (filename, char_array_str (&dirname), flags,
-                            errfunc, pglob, alloca_used);
+                            errfunc, pglob);
       if (status != 0)
         {
           if (status == GLOB_NOMATCH && flags != orig_flags
@@ -1206,7 +1199,7 @@ struct globnames_result
 static int
 glob_in_dir (const char *pattern, const char *directory, int flags,
              int (*errfunc) (const char *, int),
-             glob_t *pglob, size_t alloca_used)
+             glob_t *pglob)
 {
   void *stream = NULL;
   struct globnames_array globnames;
-- 
2.25.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]