This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] _nl_expand_alias: Remove alloca calls


2017-06-19  Florian Weimer  <fweimer@redhat.com>

	* intl/localealias.c: Remove alloca support.
	(read_alias_file): Use asprintf instead of alloca.

diff --git a/intl/localealias.c b/intl/localealias.c
index 9921aa2..36959df 100644
--- a/intl/localealias.c
+++ b/intl/localealias.c
@@ -32,30 +32,8 @@
 #endif
 #include <sys/types.h>
 
-#ifdef __GNUC__
-# undef alloca
-# define alloca __builtin_alloca
-# define HAVE_ALLOCA 1
-#else
-# ifdef _MSC_VER
-#  include <malloc.h>
-#  define alloca _alloca
-# else
-#  if defined HAVE_ALLOCA_H || defined _LIBC
-#   include <alloca.h>
-#  else
-#   ifdef _AIX
- #pragma alloca
-#   else
-#    ifndef alloca
-char *alloca ();
-#    endif
-#   endif
-#  endif
-# endif
-#endif
-
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 
 #include "gettextP.h"
@@ -101,15 +79,6 @@ char *alloca ();
 # define FGETS(buf, n, fp)	fgets (buf, n, fp)
 #endif
 
-/* For those losing systems which don't have `alloca' we have to add
-   some additional code emulating it.  */
-#ifdef HAVE_ALLOCA
-# define freea(p) /* nothing */
-#else
-# define alloca(n) malloc (n)
-# define freea(p) free (p)
-#endif
-
 #if defined _LIBC_REENTRANT || defined HAVE_DECL_FGETS_UNLOCKED
 # undef fgets
 # define fgets(buf, len, s) fgets_unlocked (buf, len, s)
@@ -218,16 +187,9 @@ read_alias_file (const char *fname, int fname_len)
   FILE *fp;
   char *full_fname;
   size_t added;
-  static const char aliasfile[] = "/locale.alias";
 
-  full_fname = (char *) alloca (fname_len + sizeof aliasfile);
-#ifdef HAVE_MEMPCPY
-  mempcpy (mempcpy (full_fname, fname, fname_len),
-	   aliasfile, sizeof aliasfile);
-#else
-  memcpy (full_fname, fname, fname_len);
-  memcpy (&full_fname[fname_len], aliasfile, sizeof aliasfile);
-#endif
+  if (__asprintf (&full_fname, "%s/locale.alias", fname) < 0)
+    return 0;
 
 #ifdef _LIBC
   /* Note the file is opened with cancellation in the I/O functions
@@ -236,7 +198,7 @@ read_alias_file (const char *fname, int fname_len)
 #else
   fp = fopen (relocate (full_fname), "r");
 #endif
-  freea (full_fname);
+  free (full_fname);
   if (fp == NULL)
     return 0;
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]