Mercurial > hg > octave-lyh > gnulib-hg
changeset 4929:4192ff0fff14
Use allocsa instead of alloca.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Tue, 20 Jan 2004 17:05:34 +0000 |
parents | 6904dd9a5ccf |
children | 242e4790a5ba |
files | ChangeLog lib/ChangeLog lib/setenv.c modules/setenv |
diffstat | 4 files changed, 42 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2004-01-20 Bruno Haible <bruno@clisp.org> + + * modules/setenv: Depend on allocsa instead of alloca. + 2004-01-20 Bruno Haible <bruno@clisp.org> * modules/xallocsa: New file.
--- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,12 @@ +2003-11-30 Bruno Haible <bruno@clisp.org> + + Safer stack allocation. + * setenv.c: Include allocsa.h. + (alloca): Remove fallback definition. + (freea): Remove macro. + (__add_to_environ) [!_LIBC]: Use allocsa instead of alloca. Use freesa + instead of freea. + 2003-10-17 Bruno Haible <bruno@clisp.org> * binary-io.h: Avoid warnings on Cygwin.
--- a/lib/setenv.c +++ b/lib/setenv.c @@ -34,13 +34,8 @@ # include <unistd.h> #endif -/* For those losing systems which don't have 'alloca' we have to add - some additional code emulating it. */ -#if _LIBC || HAVE_ALLOCA -# define freea(p) /* nothing */ -#else -# define alloca(n) malloc (n) -# define freea(p) free (p) +#if !_LIBC +# include "allocsa.h" #endif #if !_LIBC @@ -163,11 +158,18 @@ { /* See whether the value is already known. */ #ifdef USE_TSEARCH +# ifdef _LIBC new_value = (char *) alloca (namelen + 1 + vallen); -# ifdef _LIBC __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1), value, vallen); # else + new_value = (char *) allocsa (namelen + 1 + vallen); + if (new_value == NULL) + { + __set_errno (ENOMEM); + UNLOCK; + return -1; + } memcpy (new_value, name, namelen); new_value[namelen] = '='; memcpy (&new_value[namelen + 1], value, vallen); @@ -180,8 +182,8 @@ new_environ[size] = (char *) malloc (namelen + 1 + vallen); if (new_environ[size] == NULL) { -#ifdef USE_TSEARCH - freea (new_value); +#if defined USE_TSEARCH && !defined _LIBC + freesa (new_value); #endif __set_errno (ENOMEM); UNLOCK; @@ -200,8 +202,8 @@ user string or not. */ STORE_VALUE (new_environ[size]); } -#ifdef USE_TSEARCH - freea (new_value); +#if defined USE_TSEARCH && !defined _LIBC + freesa (new_value); #endif } @@ -223,11 +225,19 @@ else { #ifdef USE_TSEARCH - char *new_value = alloca (namelen + 1 + vallen); + char *new_value; # ifdef _LIBC + new_value = alloca (namelen + 1 + vallen); __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1), value, vallen); # else + new_value = allocsa (namelen + 1 + vallen); + if (new_value == NULL) + { + __set_errno (ENOMEM); + UNLOCK; + return -1; + } memcpy (new_value, name, namelen); new_value[namelen] = '='; memcpy (&new_value[namelen + 1], value, vallen); @@ -240,9 +250,10 @@ np = malloc (namelen + 1 + vallen); if (np == NULL) { -#ifdef USE_TSEARCH - freea (new_value); +#if defined USE_TSEARCH && !defined _LIBC + freesa (new_value); #endif + __set_errno (ENOMEM); UNLOCK; return -1; } @@ -257,8 +268,8 @@ /* And remember the value. */ STORE_VALUE (np); } -#ifdef USE_TSEARCH - freea (new_value); +#if defined USE_TSEARCH && !defined _LIBC + freesa (new_value); #endif }