diff options
33 files changed, 294 insertions, 63 deletions
@@ -1,3 +1,7 @@ +2003-11-30 Bruno Haible <bruno@clisp.org> + + * config/install-reloc: Compile also the allocsa.c file. + 2003-12-17 Bruno Haible <bruno@clisp.org> * gettext-0.13.1 released. diff --git a/config/install-reloc b/config/install-reloc index 8d5cc64..ad4b0eb 100755 --- a/config/install-reloc +++ b/config/install-reloc @@ -110,7 +110,7 @@ test -n "$libdirs" || exit 0 # Compile wrapper. installdir=`echo "$destprog" | sed -e 's,/[^/]*$,,'` -func_verbose $compile_command -I"$builddir" -I"$srcdir" -I"$config_h_dir" -DHAVE_CONFIG_H -DNO_XMALLOC -D"INSTALLPREFIX=\"$prefix\"" -D"INSTALLDIR=\"$installdir\"" -D"LIBPATHVAR=\"$library_path_var\"" -D"LIBDIRS=$libdirs" "$srcdir"/relocwrapper.c "$srcdir"/progname.c "$srcdir"/progreloc.c "$srcdir"/xreadlink.c "$srcdir"/readlink.c "$srcdir"/canonicalize.c "$srcdir"/relocatable.c "$srcdir"/setenv.c "$srcdir"/strerror.c -o $destprog.wrapper || exit $? +func_verbose $compile_command -I"$builddir" -I"$srcdir" -I"$config_h_dir" -DHAVE_CONFIG_H -DNO_XMALLOC -D"INSTALLPREFIX=\"$prefix\"" -D"INSTALLDIR=\"$installdir\"" -D"LIBPATHVAR=\"$library_path_var\"" -D"LIBDIRS=$libdirs" "$srcdir"/relocwrapper.c "$srcdir"/progname.c "$srcdir"/progreloc.c "$srcdir"/xreadlink.c "$srcdir"/readlink.c "$srcdir"/canonicalize.c "$srcdir"/allocsa.c "$srcdir"/relocatable.c "$srcdir"/setenv.c "$srcdir"/strerror.c -o $destprog.wrapper || exit $? # Rename $destprog.wrapper -> $destprog -> $destprog.bin. ln -f $destprog $destprog.bin || exit 1 diff --git a/gettext-runtime/ChangeLog b/gettext-runtime/ChangeLog index 066457a..f9cb83e 100644 --- a/gettext-runtime/ChangeLog +++ b/gettext-runtime/ChangeLog @@ -1,3 +1,7 @@ +2003-11-30 Bruno Haible <bruno@clisp.org> + + * configure.ac: Invoke gl_ALLOCSA instead of gl_FUNC_ALLOCA. + 2003-12-17 Bruno Haible <bruno@clisp.org> * gettext-0.13.1 released. diff --git a/gettext-runtime/configure.ac b/gettext-runtime/configure.ac index 01878e7..b733786 100644 --- a/gettext-runtime/configure.ac +++ b/gettext-runtime/configure.ac @@ -74,7 +74,7 @@ dnl Checks for typedefs, structures, and compiler characteristics. AC_TYPE_SIZE_T dnl Checks for library functions. -gl_FUNC_ALLOCA +gl_ALLOCSA AC_FUNC_VPRINTF AC_CHECK_FUNCS([setlocale strerror strtoul]) AC_REPLACE_FUNCS([atexit memmove]) diff --git a/gettext-tools/ChangeLog b/gettext-tools/ChangeLog index 82a546a..fd58612 100644 --- a/gettext-tools/ChangeLog +++ b/gettext-tools/ChangeLog @@ -1,3 +1,8 @@ +2003-11-30 Bruno Haible <bruno@clisp.org> + + * configure.ac: Invoke gl_ALLOCSA instead of gl_FUNC_ALLOCA. + * windows/gettextlib.def: Add mallocsa, xmallocsa, freesa. + 2003-12-17 Bruno Haible <bruno@clisp.org> * gettext-0.13.1 released. diff --git a/gettext-tools/configure.ac b/gettext-tools/configure.ac index 565e61c..64da59d 100644 --- a/gettext-tools/configure.ac +++ b/gettext-tools/configure.ac @@ -101,7 +101,7 @@ AC_TYPE_MODE_T gt_TYPE_SIG_ATOMIC_T dnl Checks for library functions. -gl_FUNC_ALLOCA +gl_ALLOCSA AC_FUNC_VPRINTF AC_CHECK_FUNCS([chown getcwd posix_spawn raise select strerror strtoul uname \ utime utimes waitid]) diff --git a/gettext-tools/lib/ChangeLog b/gettext-tools/lib/ChangeLog index 4c7b0d8..d138b8c 100644 --- a/gettext-tools/lib/ChangeLog +++ b/gettext-tools/lib/ChangeLog @@ -1,3 +1,30 @@ +2003-11-30 Bruno Haible <bruno@clisp.org> + + Safer stack allocation. + * allocsa.h: New file. + * allocsa.c: New file. + * xallocsa.h: New file. + * xallocsa.c: New file. + * canonicalize.c: Include allocsa.h. + (__realpath): Use allocsa instead of alloca. Don't clobber errno right + before returning NULL. + * javacomp.c: Include xallocsa.h. + (compile_java_class): Use allocsa instead of alloca. + * javaexec.c: Include xallocsa.h. + (execute_java_class): Use allocsa instead of alloca. + * relocwrapper.c: Indirectly depends on allocsa. + * 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. + * Makefile.am (libgettextlib_la_SOURCES): Add allocsa.h, allocsa.c, + xallocsa.h, xallocsa.c. + * Makefile.msvc (OBJECTS): Add allocsa.obj, xallocsa.obj. + (allocsa.obj, xallocsa.obj): New rules. + * Makefile.vms (OBJECTS): Add allocsa.obj, xallocsa.obj. + (allocsa.obj, xallocsa.obj): New rules. + 2003-12-17 Bruno Haible <bruno@clisp.org> * gettext-0.13.1 released. diff --git a/gettext-tools/lib/Makefile.am b/gettext-tools/lib/Makefile.am index fe2aedf..85e23cb 100644 --- a/gettext-tools/lib/Makefile.am +++ b/gettext-tools/lib/Makefile.am @@ -31,6 +31,7 @@ lib_LTLIBRARIES = libgettextlib.la # Sources that are compiled on all platforms. libgettextlib_la_SOURCES = \ + allocsa.h allocsa.c \ argmatch.h argmatch.c \ backupfile.h backupfile.c addext.c \ basename.h basename.c \ @@ -71,6 +72,7 @@ libgettextlib_la_SOURCES = \ unlocked-io.h \ wait-process.h wait-process.c \ xalloc.h xmalloc.c xstrdup.c \ + xallocsa.h xallocsa.c \ xerror.h xerror.c \ xreadlink.h xreadlink.c \ xsetenv.h xsetenv.c \ diff --git a/gettext-tools/lib/Makefile.msvc b/gettext-tools/lib/Makefile.msvc index 3e22de8..11b35c2 100644 --- a/gettext-tools/lib/Makefile.msvc +++ b/gettext-tools/lib/Makefile.msvc @@ -80,6 +80,7 @@ INSTALL_DATA = copy SHELL = /bin/sh OBJECTS = \ + allocsa.obj \ argmatch.obj \ backupfile.obj addext.obj \ basename.obj \ @@ -114,6 +115,7 @@ OBJECTS = \ tmpdir.obj \ wait-process.obj \ xmalloc.obj xstrdup.obj \ + xallocsa.obj \ xerror.obj \ xsetenv.obj \ \ @@ -131,6 +133,9 @@ RESOURCES = gettextlib.res all : gettextlib.lib +allocsa.obj : allocsa.c + $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c allocsa.c + argmatch.obj : argmatch.c $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c argmatch.c @@ -251,6 +256,9 @@ xmalloc.obj : xmalloc.c xstrdup.obj : xstrdup.c $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c xstrdup.c +xallocsa.obj : xallocsa.c + $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c xallocsa.c + xerror.obj : xerror.c $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c xerror.c diff --git a/gettext-tools/lib/Makefile.vms b/gettext-tools/lib/Makefile.vms index df74b4a..2872dbc 100644 --- a/gettext-tools/lib/Makefile.vms +++ b/gettext-tools/lib/Makefile.vms @@ -38,6 +38,7 @@ INSTALL_DATA = copy #### End of system configuration section. #### OBJECTS = \ + allocsa.obj, \ argmatch.obj, \ backupfile.obj, addext.obj, \ basename.obj, \ @@ -72,6 +73,7 @@ OBJECTS = \ tmpdir.obj, \ wait-process.obj, \ xmalloc.obj, xstrdup.obj, \ + xallocsa.obj, \ xerror.obj, \ xsetenv.obj, \ \ @@ -92,6 +94,9 @@ alloca.h : alloca_.h fnmatch.h : fnmatch_.h $(LN) fnmatch_.h fnmatch.h +allocsa.obj : allocsa.c + $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) allocsa.c + argmatch.obj : argmatch.c $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) argmatch.c @@ -212,6 +217,9 @@ xmalloc.obj : xmalloc.c xstrdup.obj : xstrdup.c $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) xstrdup.c +xallocsa.obj : xallocsa.c + $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) xallocsa.c + xerror.obj : xerror.c $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) xerror.c diff --git a/gettext-tools/lib/canonicalize.c b/gettext-tools/lib/canonicalize.c index 336843d..fe0cb6d 100644 --- a/gettext-tools/lib/canonicalize.c +++ b/gettext-tools/lib/canonicalize.c @@ -69,7 +69,7 @@ # define __canonicalize_file_name canonicalize_file_name # define __realpath rpl_realpath # include "pathmax.h" -# define __alloca alloca +# include "allocsa.h" # if HAVE_GETCWD # ifdef VMS /* We want the directory in Unix syntax, not in VMS syntax. */ @@ -236,7 +236,7 @@ __realpath (const char *name, char *resolved) #ifdef S_ISLNK if (S_ISLNK (st.st_mode)) { - char *buf = __alloca (path_max); + char *buf; size_t len; if (++num_links > MAXSYMLINKS) @@ -245,17 +245,38 @@ __realpath (const char *name, char *resolved) goto error; } + buf = allocsa (path_max); + if (!buf) + { + errno = ENOMEM; + goto error; + } + n = __readlink (rpath, buf, path_max); if (n < 0) - goto error; + { + int saved_errno = errno; + freesa (buf); + errno = saved_errno; + goto error; + } buf[n] = '\0'; if (!extra_buf) - extra_buf = __alloca (path_max); + { + extra_buf = allocsa (path_max); + if (!extra_buf) + { + freesa (buf); + errno = ENOMEM; + goto error; + } + } len = strlen (end); if ((long int) (n + len) >= path_max) { + freesa (buf); __set_errno (ENAMETOOLONG); goto error; } @@ -278,13 +299,22 @@ __realpath (const char *name, char *resolved) --dest; *dest = '\0'; + if (extra_buf) + freesa (extra_buf); + return resolved ? memcpy (resolved, rpath, dest - rpath + 1) : rpath; error: - if (resolved) - strcpy (resolved, rpath); - else - free (rpath); + { + int saved_errno = errno; + if (extra_buf) + freesa (extra_buf); + if (resolved) + strcpy (resolved, rpath); + else + free (rpath); + errno = saved_errno; + } return NULL; } #ifdef _LIBC diff --git a/gettext-tools/lib/javacomp.c b/gettext-tools/lib/javacomp.c index 6f50a1d..16aeaf8 100644 --- a/gettext-tools/lib/javacomp.c +++ b/gettext-tools/lib/javacomp.c @@ -36,6 +36,7 @@ #include "sh-quote.h" #include "safe-read.h" #include "xalloc.h" +#include "xallocsa.h" #include "error.h" #include "gettext.h" @@ -122,7 +123,7 @@ compile_java_class (const char * const *java_sources, command_length += 1 + shell_quote_length (java_sources[i]); command_length += 1; - command = (char *) alloca (command_length); + command = (char *) xallocsa (command_length); p = command; /* Don't shell_quote $JAVAC, because it may consist of a command and options. */ @@ -165,6 +166,8 @@ compile_java_class (const char * const *java_sources, true, true); err = (exitstatus != 0); + freesa (command); + /* Reset CLASSPATH. */ reset_classpath (old_classpath); @@ -263,7 +266,7 @@ compile_java_class (const char * const *java_sources, argc = 2 + (optimize ? 1 : 0) + (debug ? 1 : 0) + (directory != NULL ? 2 : 0) + java_sources_count; - argv = (char **) alloca ((argc + 1) * sizeof (char *)); + argv = (char **) xallocsa ((argc + 1) * sizeof (char *)); argp = argv; *argp++ = "gcj"; @@ -295,6 +298,8 @@ compile_java_class (const char * const *java_sources, true); err = (exitstatus != 0); + freesa (argv); + /* Reset CLASSPATH. */ reset_classpath (old_classpath); @@ -339,7 +344,7 @@ compile_java_class (const char * const *java_sources, argc = 1 + (optimize ? 1 : 0) + (debug ? 1 : 0) + (directory != NULL ? 2 : 0) + java_sources_count; - argv = (char **) alloca ((argc + 1) * sizeof (char *)); + argv = (char **) xallocsa ((argc + 1) * sizeof (char *)); argp = argv; *argp++ = "javac"; @@ -370,6 +375,8 @@ compile_java_class (const char * const *java_sources, true, true); err = (exitstatus != 0); + freesa (argv); + /* Reset CLASSPATH. */ reset_classpath (old_classpath); @@ -416,7 +423,7 @@ compile_java_class (const char * const *java_sources, argc = 1 + (optimize ? 1 : 0) + (debug ? 1 : 0) + (directory != NULL ? 2 : 0) + java_sources_count; - argv = (char **) alloca ((argc + 1) * sizeof (char *)); + argv = (char **) xallocsa ((argc + 1) * sizeof (char *)); argp = argv; *argp++ = "jikes"; @@ -447,6 +454,8 @@ compile_java_class (const char * const *java_sources, true, true); err = (exitstatus != 0); + freesa (argv); + /* Reset CLASSPATH. */ reset_classpath (old_classpath); diff --git a/gettext-tools/lib/javaexec.c b/gettext-tools/lib/javaexec.c index ab218de..0f56840 100644 --- a/gettext-tools/lib/javaexec.c +++ b/gettext-tools/lib/javaexec.c @@ -34,6 +34,7 @@ #include "sh-quote.h" #include "pathname.h" #include "xalloc.h" +#include "xallocsa.h" #include "error.h" #include "gettext.h" @@ -98,7 +99,7 @@ execute_java_class (const char *class_name, { char *exe_pathname = concatenated_pathname (exe_dir, class_name, EXEEXT); char *old_classpath; - char **argv = (char **) alloca ((1 + nargs + 1) * sizeof (char *)); + char **argv = (char **) xallocsa ((1 + nargs + 1) * sizeof (char *)); unsigned int i; /* Set CLASSPATH. */ @@ -122,6 +123,8 @@ execute_java_class (const char *class_name, /* Reset CLASSPATH. */ reset_classpath (old_classpath); + freesa (argv); + goto done1; } @@ -151,7 +154,7 @@ execute_java_class (const char *class_name, command_length += 1 + shell_quote_length (*arg); command_length += 1; - command = (char *) alloca (command_length); + command = (char *) xallocsa (command_length); p = command; /* Don't shell_quote $JAVA, because it may consist of a command and options. */ @@ -178,6 +181,8 @@ execute_java_class (const char *class_name, argv[3] = NULL; err = executer (java, "/bin/sh", argv, private_data); + freesa (command); + /* Reset CLASSPATH. */ reset_classpath (old_classpath); @@ -215,7 +220,7 @@ execute_java_class (const char *class_name, if (gij_present) { char *old_classpath; - char **argv = (char **) alloca ((2 + nargs + 1) * sizeof (char *)); + char **argv = (char **) xallocsa ((2 + nargs + 1) * sizeof (char *)); unsigned int i; /* Set CLASSPATH. */ @@ -240,6 +245,8 @@ execute_java_class (const char *class_name, /* Reset CLASSPATH. */ reset_classpath (old_classpath); + freesa (argv); + goto done2; } } @@ -266,7 +273,7 @@ execute_java_class (const char *class_name, if (java_present) { char *old_classpath; - char **argv = (char **) alloca ((2 + nargs + 1) * sizeof (char *)); + char **argv = (char **) xallocsa ((2 + nargs + 1) * sizeof (char *)); unsigned int i; /* Set CLASSPATH. We don't use the "-classpath ..." option because @@ -293,6 +300,8 @@ execute_java_class (const char *class_name, /* Reset CLASSPATH. */ reset_classpath (old_classpath); + freesa (argv); + goto done2; } } @@ -318,7 +327,7 @@ execute_java_class (const char *class_name, if (jre_present) { char *old_classpath; - char **argv = (char **) alloca ((2 + nargs + 1) * sizeof (char *)); + char **argv = (char **) xallocsa ((2 + nargs + 1) * sizeof (char *)); unsigned int i; /* Set CLASSPATH. We don't use the "-classpath ..." option because @@ -345,6 +354,8 @@ execute_java_class (const char *class_name, /* Reset CLASSPATH. */ reset_classpath (old_classpath); + freesa (argv); + goto done2; } } @@ -373,7 +384,7 @@ execute_java_class (const char *class_name, if (jview_present) { char *old_classpath; - char **argv = (char **) alloca ((2 + nargs + 1) * sizeof (char *)); + char **argv = (char **) xallocsa ((2 + nargs + 1) * sizeof (char *)); unsigned int i; /* Set CLASSPATH. */ @@ -398,6 +409,8 @@ execute_java_class (const char *class_name, /* Reset CLASSPATH. */ reset_classpath (old_classpath); + freesa (argv); + goto done2; } } diff --git a/gettext-tools/lib/relocwrapper.c b/gettext-tools/lib/relocwrapper.c index 684442c..c4002f8 100644 --- a/gettext-tools/lib/relocwrapper.c +++ b/gettext-tools/lib/relocwrapper.c @@ -23,8 +23,10 @@ -> xreadlink -> readlink -> canonicalize + -> allocsa -> relocatable -> setenv + -> allocsa -> strerror Macros that need to be set while compiling this file: diff --git a/gettext-tools/lib/setenv.c b/gettext-tools/lib/setenv.c index 7c8ab7a..f2082cd 100644 --- a/gettext-tools/lib/setenv.c +++ b/gettext-tools/lib/setenv.c @@ -39,13 +39,8 @@ extern int errno; # 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 @@ -168,11 +163,18 @@ __add_to_environ (const char *name, const char *value, const char *combined, { /* See whether the value is already known. */ #ifdef USE_TSEARCH - new_value = (char *) alloca (namelen + 1 + vallen); # ifdef _LIBC + new_value = (char *) alloca (namelen + 1 + vallen); __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); @@ -185,8 +187,8 @@ __add_to_environ (const char *name, const char *value, const char *combined, 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; @@ -205,8 +207,8 @@ __add_to_environ (const char *name, const char *value, const char *combined, 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 } @@ -228,11 +230,19 @@ __add_to_environ (const char *name, const char *value, const char *combined, 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); @@ -245,9 +255,10 @@ __add_to_environ (const char *name, const char *value, const char *combined, 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; } @@ -262,8 +273,8 @@ __add_to_environ (const char *name, const char *value, const char *combined, /* And remember the value. */ STORE_VALUE (np); } -#ifdef USE_TSEARCH - freea (new_value); +#if defined USE_TSEARCH && !defined _LIBC + freesa (new_value); #endif } diff --git a/gettext-tools/m4/ChangeLog b/gettext-tools/m4/ChangeLog index 8c48707..6f1ac94 100644 --- a/gettext-tools/m4/ChangeLog +++ b/gettext-tools/m4/ChangeLog @@ -1,3 +1,11 @@ +2003-11-30 Bruno Haible <bruno@clisp.org> + + * allocsa.m4: New file. + * eealloc.m4: New file. + * setenv.m4 (gl_PREREQ_SETENV): Require gl_ALLOCSA instead of + AC_FUNC_ALLOCA. + * Makefile.am (EXTRA_DIST): Add allocsa.m4, eealloc.m4. + 2003-12-17 Bruno Haible <bruno@clisp.org> * gettext-0.13.1 released. diff --git a/gettext-tools/m4/Makefile.am b/gettext-tools/m4/Makefile.am index 8c6fdea..9e8f990 100644 --- a/gettext-tools/m4/Makefile.am +++ b/gettext-tools/m4/Makefile.am @@ -43,9 +43,11 @@ examplesconfig_DATA = gcj.m4 javacomp.m4 javaexec.m4 # find . -type f -name '*.m4' -printf '%f\n' | sort | tr '\012' @ | sed 's/@$/%/;s/@/ \\@/g' | tr @% '\012\012' EXTRA_DIST = README ChangeLog.0 \ alloca.m4 \ +allocsa.m4 \ backupfile.m4 \ canonicalize.m4 \ eaccess.m4 \ +eealloc.m4 \ error.m4 \ extensions.m4 \ fnmatch.m4 \ diff --git a/gettext-tools/m4/setenv.m4 b/gettext-tools/m4/setenv.m4 index af621ec..6c30589 100644 --- a/gettext-tools/m4/setenv.m4 +++ b/gettext-tools/m4/setenv.m4 @@ -1,5 +1,5 @@ -# setenv.m4 serial 3 -dnl Copyright (C) 2001-2002 Free Software Foundation, Inc. +# setenv.m4 serial 4 +dnl Copyright (C) 2001-2003 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General dnl Public License, this file may be distributed as part of a program @@ -39,7 +39,7 @@ AC_DEFUN([gt_CHECK_VAR_DECL], # Prerequisites of lib/setenv.c. AC_DEFUN([gl_PREREQ_SETENV], [ - AC_REQUIRE([AC_FUNC_ALLOCA]) + AC_REQUIRE([gl_ALLOCSA]) AC_CHECK_HEADERS_ONCE(stdlib.h string.h unistd.h) AC_CHECK_HEADERS(search.h) AC_CHECK_FUNCS(tsearch) diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index b9e66b9..598cba8 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,37 @@ +2003-11-30 Bruno Haible <bruno@clisp.org> + + * format-java.c: Include xallocsa.h. + (message_format_parse): Use xallocsa instead of alloca. + (choice_format_parse): Likewise. + * msgl-cat.c: Include xallocsa.h. + (catenate_msgdomain_list): Use xallocsa instead of alloca. + * msgl-charset.c: Include xallocsa.h. + (compare_po_locale_charsets): Use xallocsa instead of alloca. + * msgl-iconv.c: Include xallocsa.h. + (iconv_message_list): Use xallocsa instead of alloca. + * po-charset.c: Include xallocsa.h. + (po_lex_charset_set): Use xallocsa instead of alloca. + * read-tcl.c: Include xallocsa.h. + (msgdomain_read_tcl): Use xallocsa instead of alloca. + * write-java.c: Include xallocsa.h. + (compute_hashsize, msgdomain_write_java): Use xallocsa instead of + alloca. + * write-mo.c: Include xallocsa.h. + (write_table): Use xallocsa instead of alloca. + * write-po.c: Include xallocsa.h. + (msgdomain_list_print_po): Use xallocsa instead of alloca. + * write-tcl.c: Include xallocsa.h. + (msgdomain_write_tcl): Use xallocsa instead of alloca. + * msggrep.c: Include xallocsa.h. + (is_message_selected): Use xallocsa instead of alloca. + * msginit.c: Include xallocsa.h. + (subst_string): Use xallocsa instead of alloca. + * msgmerge.c: Include obstack.h. + (obstack_chunk_alloc, obstack_chunk_free): New macros. + (message_merge): Use obstack_alloc instead of alloca. + * xgettext.c: Include xallocsa.h. + (flag_context_list_table_insert): Use xallocsa instead of alloca. + 2003-12-17 Bruno Haible <bruno@clisp.org> * gettext-0.13.1 released. diff --git a/gettext-tools/src/format-java.c b/gettext-tools/src/format-java.c index 7425687..c8b9535 100644 --- a/gettext-tools/src/format-java.c +++ b/gettext-tools/src/format-java.c @@ -28,6 +28,7 @@ #include "format.h" #include "c-ctype.h" #include "xalloc.h" +#include "xallocsa.h" #include "xerror.h" #include "format-invalid.h" #include "error.h" @@ -193,7 +194,7 @@ message_format_parse (const char *format, struct spec *spec, element_end = format++; n = element_end - element_start; - element = (char *) alloca (n + 1); + element = (char *) xallocsa (n + 1); memcpy (element, element_start, n); element[n] = '\0'; @@ -201,6 +202,7 @@ message_format_parse (const char *format, struct spec *spec, { *invalid_reason = xasprintf (_("In the directive number %u, '{' is not followed by an argument number."), spec->directives); + freesa (element); return false; } number = 0; @@ -234,6 +236,7 @@ message_format_parse (const char *format, struct spec *spec, { *invalid_reason = xasprintf (_("In the directive number %u, the substring \"%s\" is not a valid date/time style."), spec->directives, element); + freesa (element); return false; } } @@ -243,6 +246,7 @@ message_format_parse (const char *format, struct spec *spec, element -= 4; *invalid_reason = xasprintf (_("In the directive number %u, \"%s\" is not followed by a comma."), spec->directives, element); + freesa (element); return false; } } @@ -264,6 +268,7 @@ message_format_parse (const char *format, struct spec *spec, { *invalid_reason = xasprintf (_("In the directive number %u, the substring \"%s\" is not a valid number style."), spec->directives, element); + freesa (element); return false; } } @@ -273,6 +278,7 @@ message_format_parse (const char *format, struct spec *spec, element -= 6; *invalid_reason = xasprintf (_("In the directive number %u, \"%s\" is not followed by a comma."), spec->directives, element); + freesa (element); return false; } } @@ -288,7 +294,10 @@ message_format_parse (const char *format, struct spec *spec, if (choice_format_parse (element, spec, invalid_reason)) ; else - return false; + { + freesa (element); + return false; + } } else { @@ -296,6 +305,7 @@ message_format_parse (const char *format, struct spec *spec, element -= 6; *invalid_reason = xasprintf (_("In the directive number %u, \"%s\" is not followed by a comma."), spec->directives, element); + freesa (element); return false; } } @@ -303,8 +313,10 @@ message_format_parse (const char *format, struct spec *spec, { *invalid_reason = xasprintf (_("In the directive number %u, the argument number is not followed by a comma and one of \"%s\", \"%s\", \"%s\", \"%s\"."), spec->directives, "time", "date", "number", "choice"); + freesa (element); return false; } + freesa (element); if (spec->allocated == spec->numbered_arg_count) { @@ -511,6 +523,7 @@ choice_format_parse (const char *format, struct spec *spec, bool number_nonempty; char *msgformat; char *mp; + bool msgformat_valid; /* Parse number. */ number_nonempty = false; @@ -559,7 +572,7 @@ choice_format_parse (const char *format, struct spec *spec, } HANDLE_QUOTE; - msgformat = (char *) alloca (strlen (format) + 1); + msgformat = (char *) xallocsa (strlen (format) + 1); mp = msgformat; while (*format != '\0' && !(!quoting && *format == '|')) @@ -569,7 +582,11 @@ choice_format_parse (const char *format, struct spec *spec, } *mp = '\0'; - if (!message_format_parse (msgformat, spec, invalid_reason)) + msgformat_valid = message_format_parse (msgformat, spec, invalid_reason); + + freesa (msgformat); + + if (!msgformat_valid) return false; if (*format == '\0') diff --git a/gettext-tools/src/msggrep.c b/gettext-tools/src/msggrep.c index 0b5c29b..7676270 100644 --- a/gettext-tools/src/msggrep.c +++ b/gettext-tools/src/msggrep.c @@ -51,6 +51,7 @@ #include "str-list.h" #include "msgl-charset.h" #include "xalloc.h" +#include "xallocsa.h" #include "exit.h" #include "full-write.h" #include "findprog.h" @@ -659,11 +660,12 @@ is_message_selected (const message_ty *mp) char *total_comment; char *q; size_t j; + bool selected; length = 0; for (j = 0; j < mp->comment->nitems; j++) length += strlen (mp->comment->item[j]) + 1; - total_comment = (char *) alloca (length); + total_comment = (char *) xallocsa (length); q = total_comment; for (j = 0; j < mp->comment->nitems; j++) @@ -677,7 +679,11 @@ is_message_selected (const message_ty *mp) if (q != total_comment + length) abort (); - if (is_string_selected (2, total_comment, length)) + selected = is_string_selected (2, total_comment, length); + + freesa (total_comment); + + if (selected) return true; } diff --git a/gettext-tools/src/msginit.c b/gettext-tools/src/msginit.c index 45e2554..0aa4418 100644 --- a/gettext-tools/src/msginit.c +++ b/gettext-tools/src/msginit.c @@ -86,6 +86,7 @@ #include "po-time.h" #include "plural-table.h" #include "xalloc.h" +#include "xallocsa.h" #include "exit.h" #include "pathname.h" #include "xerror.h" @@ -1581,7 +1582,7 @@ subst_string (const char *str, size_t i; unsigned int j; - substlen = (size_t *) alloca (nsubst * sizeof (size_t)); + substlen = (size_t *) xallocsa (nsubst * sizeof (size_t)); for (j = 0; j < nsubst; j++) { substlen[j] = strlen (subst[j][0]); @@ -1613,6 +1614,8 @@ subst_string (const char *str, if (j == nsubst) i++; } + + freesa (substlen); } return str; diff --git a/gettext-tools/src/msgl-cat.c b/gettext-tools/src/msgl-cat.c index c6d9742..902bd6e 100644 --- a/gettext-tools/src/msgl-cat.c +++ b/gettext-tools/src/msgl-cat.c @@ -38,6 +38,7 @@ #include "msgl-equal.h" #include "msgl-iconv.h" #include "xalloc.h" +#include "xallocsa.h" #include "strstr.h" #include "basename.h" #include "exit.h" @@ -152,7 +153,7 @@ catenate_msgdomain_list (string_list_ty *file_list, const char *to_code) charsetstr += strlen ("charset="); len = strcspn (charsetstr, " \t\n"); - charset = (char *) alloca (len + 1); + charset = (char *) xallocsa (len + 1); memcpy (charset, charsetstr, len); charset[len] = '\0'; @@ -177,6 +178,8 @@ present charset \"%s\" is not a portable encoding name"), charset); } + freesa (charset); + if (canon_from_code == NULL) canon_from_code = canon_charset; else if (canon_from_code != canon_charset) diff --git a/gettext-tools/src/msgl-charset.c b/gettext-tools/src/msgl-charset.c index 582193c..114f877 100644 --- a/gettext-tools/src/msgl-charset.c +++ b/gettext-tools/src/msgl-charset.c @@ -33,6 +33,7 @@ #include "error.h" #include "progname.h" #include "basename.h" +#include "xallocsa.h" #include "xerror.h" #include "message.h" #include "strstr.h" @@ -75,7 +76,7 @@ compare_po_locale_charsets (const msgdomain_list_ty *mdlp) charsetstr += strlen ("charset="); len = strcspn (charsetstr, " \t\n"); - charset = (char *) alloca (len + 1); + charset = (char *) xallocsa (len + 1); memcpy (charset, charsetstr, len); charset[len] = '\0'; @@ -85,6 +86,7 @@ compare_po_locale_charsets (const msgdomain_list_ty *mdlp) _("\ present charset \"%s\" is not a portable encoding name"), charset); + freesa (charset); if (canon_locale_code != canon_charset) { multiline_warning (xasprintf (_("warning: ")), diff --git a/gettext-tools/src/msgl-iconv.c b/gettext-tools/src/msgl-iconv.c index 5eb99ff..d5f93b7 100644 --- a/gettext-tools/src/msgl-iconv.c +++ b/gettext-tools/src/msgl-iconv.c @@ -41,6 +41,7 @@ #include "po-charset.h" #include "msgl-ascii.h" #include "xalloc.h" +#include "xallocsa.h" #include "strstr.h" #include "exit.h" #include "gettext.h" @@ -279,7 +280,7 @@ iconv_message_list (message_list_ty *mlp, charsetstr += strlen ("charset="); len = strcspn (charsetstr, " \t\n"); - charset = (char *) alloca (len + 1); + charset = (char *) xallocsa (len + 1); memcpy (charset, charsetstr, len); charset[len] = '\0'; @@ -316,6 +317,7 @@ present charset \"%s\" is not a portable encoding name"), two different charsets \"%s\" and \"%s\" in input file"), canon_from_code, canon_charset); } + freesa (charset); len1 = charsetstr - header; len2 = strlen (canon_to_code); diff --git a/gettext-tools/src/po-charset.c b/gettext-tools/src/po-charset.c index 33023ee..4399a86 100644 --- a/gettext-tools/src/po-charset.c +++ b/gettext-tools/src/po-charset.c @@ -28,6 +28,7 @@ #include <stdlib.h> #include <string.h> +#include "xallocsa.h" #include "xerror.h" #include "basename.h" #include "progname.h" @@ -207,7 +208,7 @@ po_lex_charset_set (const char *header_entry, const char *filename) charsetstr += strlen ("charset="); len = strcspn (charsetstr, " \t\n"); - charset = (char *) alloca (len + 1); + charset = (char *) xallocsa (len + 1); memcpy (charset, charsetstr, len); charset[len] = '\0'; @@ -336,6 +337,7 @@ would fix this problem.\n"))); #endif } } + freesa (charset); } else { diff --git a/gettext-tools/src/read-tcl.c b/gettext-tools/src/read-tcl.c index a0dcf29..4d41678 100644 --- a/gettext-tools/src/read-tcl.c +++ b/gettext-tools/src/read-tcl.c @@ -35,6 +35,7 @@ #include "pipe.h" #include "wait-process.h" #include "read-po.h" +#include "xallocsa.h" #include "error.h" #include "exit.h" #include "gettext.h" @@ -73,7 +74,7 @@ msgdomain_read_tcl (const char *locale_name, const char *directory) /* Convert the locale name to lowercase and remove any encoding. */ len = strlen (locale_name); - frobbed_locale_name = (char *) alloca (len + 1); + frobbed_locale_name = (char *) xallocsa (len + 1); memcpy (frobbed_locale_name, locale_name, len + 1); for (p = frobbed_locale_name; *p != '\0'; p++) if (*p >= 'A' && *p <= 'Z') @@ -86,6 +87,8 @@ msgdomain_read_tcl (const char *locale_name, const char *directory) file_name = concatenated_pathname (directory, frobbed_locale_name, ".msg"); + freesa (frobbed_locale_name); + /* Prepare arguments. */ argv[0] = "tclsh"; argv[1] = tclscript; diff --git a/gettext-tools/src/write-java.c b/gettext-tools/src/write-java.c index bbf2090..5015bd7 100644 --- a/gettext-tools/src/write-java.c +++ b/gettext-tools/src/write-java.c @@ -78,6 +78,7 @@ #include "plural-exp.h" #include "po-charset.h" #include "xalloc.h" +#include "xallocsa.h" #include "pathname.h" #include "fatal-signal.h" #include "fwriteerror.h" @@ -158,7 +159,8 @@ compute_hashsize (message_list_ty *mlp, bool *collisionp) #define XXN 3 /* can be tweaked */ #define XXS 3 /* can be tweaked */ unsigned int n = mlp->nitems; - unsigned int *hashcodes = (unsigned int *) alloca (n * sizeof (unsigned int)); + unsigned int *hashcodes = + (unsigned int *) xallocsa (n * sizeof (unsigned int)); unsigned int hashsize; unsigned int best_hashsize; unsigned int best_score; @@ -275,6 +277,8 @@ compute_hashsize (message_list_ty *mlp, bool *collisionp) if (best_hashsize == 0 || best_score < best_hashsize) abort (); + freesa (hashcodes); + /* There are collisions if and only if best_score > best_hashsize. */ *collisionp = (best_score > best_hashsize); return best_hashsize; @@ -970,7 +974,7 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding, } /* Create a temporary directory where we can put the Java file. */ - template = (char *) alloca (PATH_MAX); + template = (char *) xallocsa (PATH_MAX); if (path_search (template, PATH_MAX, NULL, "msg", 1)) { error (0, errno, @@ -1010,7 +1014,7 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding, else class_name = xstrdup (resource_name); - subdirs = (ndots > 0 ? (char **) alloca (ndots * sizeof (char *)) : NULL); + subdirs = (ndots > 0 ? (char **) xallocsa (ndots * sizeof (char *)) : NULL); { const char *p; const char *last_dir; @@ -1022,10 +1026,11 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding, { const char *q = strchr (p, '.'); size_t n = q - p; - char *part = (char *) alloca (n + 1); + char *part = (char *) xallocsa (n + 1); memcpy (part, p, n); part[n] = '\0'; subdirs[i] = concatenated_pathname (last_dir, part, NULL); + freesa (part); last_dir = subdirs[i]; p = q + 1; } @@ -1113,11 +1118,13 @@ compilation of Java class failed, please try --verbose or set $JAVAC")); for (i = 0; i < ndots; i++) free (subdirs[i]); } + freesa (subdirs); free (class_name); quit2: rmdir (tmpdir); quit1: cleanup_list.tmpdir = NULL; + freesa (template); /* Here we could unregister the cleanup() handler. */ return retval; } diff --git a/gettext-tools/src/write-mo.c b/gettext-tools/src/write-mo.c index f850307..7402c28 100644 --- a/gettext-tools/src/write-mo.c +++ b/gettext-tools/src/write-mo.c @@ -43,6 +43,7 @@ #include "message.h" #include "format.h" #include "xalloc.h" +#include "xallocsa.h" #include "binary-io.h" #include "fwriteerror.h" #include "exit.h" @@ -560,8 +561,8 @@ write_table (FILE *output_file, message_list_ty *mlp) struct pre_sysdep_string *pre = msg->str[m]; struct sysdep_string *str = (struct sysdep_string *) - alloca (sizeof (struct sysdep_string) - + pre->segmentcount * sizeof (struct segment_pair)); + xallocsa (sizeof (struct sysdep_string) + + pre->segmentcount * sizeof (struct segment_pair)); unsigned int i; offset = roundup (offset, alignment); @@ -582,7 +583,7 @@ write_table (FILE *output_file, message_list_ty *mlp) + pre->segmentcount * sizeof (struct segment_pair), 1, output_file); - freea (str); + freesa (str); } } diff --git a/gettext-tools/src/write-po.c b/gettext-tools/src/write-po.c index 68c02cd..54a9f94 100644 --- a/gettext-tools/src/write-po.c +++ b/gettext-tools/src/write-po.c @@ -42,6 +42,7 @@ #include "write-properties.h" #include "write-stringtable.h" #include "xalloc.h" +#include "xallocsa.h" #include "strstr.h" #include "fwriteerror.h" #include "exit.h" @@ -955,6 +956,7 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, FILE *fp, bool debug) message_list_ty *mlp; const char *header; char *charset; + char *allocated_charset; /* If the first domain is the default, don't bother emitting the domain name, because it is the default. */ @@ -980,6 +982,7 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, FILE *fp, bool debug) /* Extract the charset name. */ charset = "ASCII"; + allocated_charset = NULL; if (header != NULL) { const char *charsetstr = strstr (header, "charset="); @@ -990,7 +993,7 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, FILE *fp, bool debug) charsetstr += strlen ("charset="); len = strcspn (charsetstr, " \t\n"); - charset = (char *) alloca (len + 1); + charset = allocated_charset = (char *) xallocsa (len + 1); memcpy (charset, charsetstr, len); charset[len] = '\0'; @@ -1015,6 +1018,9 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, FILE *fp, bool debug) message_print_obsolete (mlp->item[j], fp, charset, blank_line); blank_line = true; } + + if (allocated_charset != NULL) + freesa (allocated_charset); } } diff --git a/gettext-tools/src/write-tcl.c b/gettext-tools/src/write-tcl.c index 9b8b8f7..b75287d 100644 --- a/gettext-tools/src/write-tcl.c +++ b/gettext-tools/src/write-tcl.c @@ -35,6 +35,7 @@ #include "msgl-iconv.h" #include "po-charset.h" #include "xalloc.h" +#include "xallocsa.h" #include "pathname.h" #include "fwriteerror.h" #include "exit.h" @@ -174,7 +175,7 @@ but the Tcl message catalog format doesn't support plural handling\n"))); /* Convert the locale name to lowercase and remove any encoding. */ len = strlen (locale_name); - frobbed_locale_name = (char *) alloca (len + 1); + frobbed_locale_name = (char *) xallocsa (len + 1); memcpy (frobbed_locale_name, locale_name, len + 1); for (p = frobbed_locale_name; *p != '\0'; p++) if (*p >= 'A' && *p <= 'Z') @@ -192,6 +193,7 @@ but the Tcl message catalog format doesn't support plural handling\n"))); { error (0, errno, _("error while opening \"%s\" for writing"), file_name); + freesa (frobbed_locale_name); return 1; } @@ -203,6 +205,7 @@ but the Tcl message catalog format doesn't support plural handling\n"))); file_name); fclose (output_file); + freesa (frobbed_locale_name); } return 0; diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index b464f2d..b65300c 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -44,6 +44,7 @@ #include "basename.h" #include "xerror.h" #include "xalloc.h" +#include "xallocsa.h" #include "strstr.h" #include "xerror.h" #include "exit.h" @@ -1101,11 +1102,13 @@ flag_context_list_table_insert (flag_context_list_table_ty *table, const char *name_start, const char *name_end, int argnum, enum is_format value, bool pass) { + char *allocated_name = NULL; + if (table == &flag_table_lisp) { /* Convert NAME to upper case. */ size_t name_len = name_end - name_start; - char *name = (char *) alloca (name_len); + char *name = allocated_name = (char *) xallocsa (name_len); size_t i; for (i = 0; i < name_len; i++) @@ -1232,6 +1235,9 @@ flag_context_list_table_insert (flag_context_list_table_ty *table, } } } + + if (allocated_name != NULL) + freesa (allocated_name); } diff --git a/gettext-tools/windows/gettextlib.def b/gettext-tools/windows/gettextlib.def index 455c810..0afc408 100644 --- a/gettext-tools/windows/gettextlib.def +++ b/gettext-tools/windows/gettextlib.def @@ -48,6 +48,7 @@ execute_java_class find_backup_file_name find_entry find_in_path +freesa fstrcmp full_write fwriteerror @@ -61,6 +62,7 @@ init_hash insert_entry iterate_table locale_charset +mallocsa maybe_print_progname mbs_width_linebreaks mbsnwidth @@ -100,6 +102,7 @@ xasprintf xcalloc xget_version xmalloc +xmallocsa xrealloc xsetenv xstrdup |