Message ID | 20170619161854.A214C402AEC0E@oldenburg.str.redhat.com |
---|---|
State | New |
Headers | show |
On 19/06/2017 13:18, Florian Weimer wrote: > 2017-06-19 Florian Weimer <fweimer@redhat.com> > > * intl/localealias.c: Remove alloca support. > (read_alias_file): Use asprintf instead of alloca. I think we can use char_array on this: [...] FILE *fp = NULL; struct char_array full_fname; if (char_array_init_str (&full_fname, fname) || char_array_append_str (&full_fname, "/locale.alias")) { /* Note the file is opened with cancellation in the I/O functions disabled. */ #ifdef _LIBC # define ALIAS_MODE "ce" #else # define ALIAS_MODE "" #endif fp = fopen (relocate (char_array_str (&full_fname)), "r" ALIAS_MODE); } char_array_free (&full_fname); if (fp == NULL) return 0; [...] > > 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; > >
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;