This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] _nl_expand_alias: Remove alloca calls
- From: fweimer at redhat dot com (Florian Weimer)
- To: libc-alpha at sourceware dot org
- Date: Mon, 19 Jun 2017 18:18:54 +0200
- Subject: [PATCH] _nl_expand_alias: Remove alloca calls
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=fweimer at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6666281243
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6666281243
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;