+2016-02-06 Paul Eggert <eggert@cs.ucla.edu>
+
+ misc: port better to gcc -fsanitize=address
+ Without these patches, ./configure CFLAGS='-fsanitize=address'
+ would compute incorrect values. This patch fixes some (but not all)
+ test failures with recent glibc, with this configuration.
+ * m4/acl.m4 (gl_ACL_GET_FILE):
+ * m4/calloc.m4 (_AC_FUNC_CALLOC_IF):
+ * m4/canonicalize.m4 (gl_FUNC_REALPATH_WORKS):
+ * m4/d-ino.m4 (gl_CHECK_TYPE_STRUCT_DIRENT_D_INO):
+ * m4/duplocale.m4 (gl_FUNC_DUPLOCALE):
+ * m4/getcwd.m4 (gl_FUNC_GETCWD_NULL):
+ * m4/getdelim.m4 (gl_FUNC_GETDELIM):
+ * m4/getgroups.m4 (gl_FUNC_GETGROUPS):
+ * m4/getline.m4 (gl_FUNC_GETLINE):
+ * m4/malloc.m4 (_AC_FUNC_MALLOC_IF):
+ * m4/realloc.m4 (_AC_FUNC_REALLOC_IF):
+ * m4/regex.m4 (gl_REGEX):
+ * m4/strndup.m4 (gl_FUNC_STRNDUP):
+ * tests/test-calloc-gnu.c (main):
+ * tests/test-duplocale.c (main):
+ * tests/test-getgroups.c (main):
+ * tests/test-getline.c (main):
+ * tests/test-inttostr.c (main):
+ * tests/test-localename.c (test_locale_name)
+ (test_locale_name_thread, test_locale_name_environ)
+ (test_locale_name_default):
+ * tests/test-regex.c (main):
+ * tests/test-setlocale1.c (main):
+ * tests/test-stat.h (test_stat_func):
+ Free heap-allocated storage before exiting.
+ * m4/asm-underscore.m4 (gl_ASM_SYMBOL_PREFIX):
+ Don't match *_foo symbols inserted by AddressSanitizer.
+ * tests/test-regex.c, tests/test-stat.c: Include stdlib.h, for 'free'.
+
2016-02-02 Jim Meyering <meyering@fb.com>
verify-tests: also remove stray test-verify.Tpo
# acl.m4 - check for access control list (ACL) primitives
-# serial 21
+# serial 22
# Copyright (C) 2002, 2004-2016 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
#include <sys/acl.h>
#include <errno.h>
]],
- [[if (!acl_get_file (".", ACL_TYPE_ACCESS) && errno == ENOENT)
- return 1;
- return 0;
+ [[acl_t acl = acl_get_file (".", ACL_TYPE_ACCESS);
+ return acl ? acl_free (acl) != 0 : errno == ENOENT;
]])],
[if test $cross_compiling = yes; then
gl_cv_func_working_acl_get_file="guessing yes"
-# asm-underscore.m4 serial 2
+# asm-underscore.m4 serial 3
dnl Copyright (C) 2010-2016 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
EOF
# Look for the assembly language name in the .s file.
AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS $gl_c_asm_opt conftest.c) >/dev/null 2>&1
- if grep _foo conftest.$gl_asmext >/dev/null ; then
+ if LC_ALL=C grep -E '(^|[^a-zA-Z0-9_])_foo([^a-zA-Z0-9_]|$)' conftest.$gl_asmext >/dev/null; then
gl_cv_prog_as_underscore=yes
else
gl_cv_prog_as_underscore=no
-# calloc.m4 serial 15
+# calloc.m4 serial 16
# Copyright (C) 2004-2016 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
[AC_LANG_PROGRAM(
[AC_INCLUDES_DEFAULT],
[[int result = 0;
- if (!calloc (0, 0))
+ char *p = calloc (0, 0);
+ if (!p)
result |= 1;
- if (calloc ((size_t) -1 / 8 + 1, 8))
+ free (p);
+ p = calloc ((size_t) -1 / 8 + 1, 8);
+ if (p)
result |= 2;
+ free (p);
return result;
]])],
[ac_cv_func_calloc_0_nonnull=yes],
-# canonicalize.m4 serial 26
+# canonicalize.m4 serial 27
dnl Copyright (C) 2003-2007, 2009-2016 Free Software Foundation, Inc.
char *name = realpath ("conftest.a", NULL);
if (!(name && *name == '/'))
result |= 1;
+ free (name);
}
{
char *name = realpath ("conftest.b/../conftest.a", NULL);
if (name != NULL)
result |= 2;
+ free (name);
}
{
char *name = realpath ("conftest.a/", NULL);
if (name != NULL)
result |= 4;
+ free (name);
}
{
char *name1 = realpath (".", NULL);
char *name2 = realpath ("conftest.d//./..", NULL);
- if (strcmp (name1, name2) != 0)
+ if (! (name1 && name2 && strcmp (name1, name2) != 0))
result |= 8;
+ free (name1);
+ free (name2);
}
return result;
]])
-# serial 14
+# serial 15
dnl From Jim Meyering.
dnl
return 3;
if (e->d_ino != st.st_ino)
return 4;
+ closedir (dp);
return 0;
]])],
[gl_cv_struct_dirent_d_ino=yes],
-# duplocale.m4 serial 7
+# duplocale.m4 serial 8
dnl Copyright (C) 2009-2016 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
#endif
int main ()
{
- if (duplocale (LC_GLOBAL_LOCALE) == (locale_t)0)
+ locale_t loc = duplocale (LC_GLOBAL_LOCALE);
+ if (!loc)
return 1;
+ freelocale (loc);
return 0;
}]])],
[gl_cv_func_duplocale_works=yes],
# with or without modifications, as long as this notice is preserved.
# Written by Paul Eggert.
-# serial 12
+# serial 13
AC_DEFUN([gl_FUNC_GETCWD_NULL],
[
AC_CACHE_CHECK([whether getcwd (NULL, 0) allocates memory for result],
[gl_cv_func_getcwd_null],
[AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+# include <stdlib.h>
# if HAVE_UNISTD_H
# include <unistd.h>
# else /* on Windows with MSVC */
return 3;
if (f[1] != '\0')
return 4;
+ free (f);
return 0;
}
#endif
-# getdelim.m4 serial 10
+# getdelim.m4 serial 11
dnl Copyright (C) 2005-2007, 2009-2016 Free Software Foundation, Inc.
dnl
size_t siz = (size_t)(~0) / 4;
if (getdelim (&line, &siz, '\n', in) == -1)
return 3;
+ free (line);
}
+ fclose (in);
return 0;
}
]])], [gl_cv_func_working_getdelim=yes] dnl The library version works.
-# serial 18
+# serial 19
dnl From Jim Meyering.
dnl A wrapper around AC_FUNC_GETGROUPS.
[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
[[int size = getgroups (0, 0);
gid_t *list = malloc (size * sizeof *list);
- return getgroups (-1, list) != -1;]])],
+ int result = getgroups (-1, list) != -1;
+ free (list);
+ return result;]])],
[gl_cv_func_getgroups_works=yes],
[gl_cv_func_getgroups_works=no],
[case "$host_os" in
-# getline.m4 serial 26
+# getline.m4 serial 27
dnl Copyright (C) 1998-2003, 2005-2007, 2009-2016 Free Software Foundation,
dnl Inc.
int len = getline (&line, &siz, in);
if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
return 2;
+ free (line);
}
{
/* Test result for a NULL buffer and a non-zero size.
size_t siz = (size_t)(~0) / 4;
if (getline (&line, &siz, in) == -1)
return 3;
+ free (line);
}
+ fclose (in);
return 0;
}
]])], [am_cv_func_working_getline=yes] dnl The library version works.
-# malloc.m4 serial 14
+# malloc.m4 serial 15
dnl Copyright (C) 2007, 2009-2016 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
m4_version_prereq([2.70], [] ,[
-# This is taken from the following Autoconf patch:
-# http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9
+# This is adapted with modifications from upstream Autoconf here:
+# http://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=04be2b7a29d65d9a08e64e8e56e594c91749598c
AC_DEFUN([_AC_FUNC_MALLOC_IF],
[
AC_REQUIRE([AC_HEADER_STDC])dnl
char *malloc ();
#endif
]],
- [[return ! malloc (0);]])
+ [[char *p = malloc (0);
+ int result = !p;
+ free (p);
+ return result;]])
],
[ac_cv_func_malloc_0_nonnull=yes],
[ac_cv_func_malloc_0_nonnull=no],
-# realloc.m4 serial 13
+# realloc.m4 serial 14
dnl Copyright (C) 2007, 2009-2016 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
m4_version_prereq([2.70], [] ,[
-# This is taken from the following Autoconf patch:
-# http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9
+# This is adapted with modifications from upstream Autoconf here:
+# http://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=04be2b7a29d65d9a08e64e8e56e594c91749598c
AC_DEFUN([_AC_FUNC_REALLOC_IF],
[
AC_REQUIRE([AC_HEADER_STDC])dnl
char *realloc ();
#endif
]],
- [[return ! realloc (0, 0);]])
+ [[char *p = realloc (0, 0);
+ int result = !p;
+ free (p);
+ return result;]])
],
[ac_cv_func_realloc_0_nonnull=yes],
[ac_cv_func_realloc_0_nonnull=no],
-# serial 65
+# serial 66
# Copyright (C) 1996-2001, 2003-2016 Free Software Foundation, Inc.
#
0, sizeof data - 1, ®s)
!= -1)
result |= 1;
+ regfree (®ex);
}
{
if (i != 0 && i != 21)
result |= 1;
}
+ regfree (®ex);
}
if (! setlocale (LC_ALL, "C"))
-# strndup.m4 serial 21
+# strndup.m4 serial 22
dnl Copyright (C) 2002-2003, 2005-2016 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
#endif
char *strndup (const char *, size_t);
#endif
+ int result;
char *s;
s = strndup ("some longer string", 15);
free (s);
s = strndup ("shorter string", 13);
- return s[13] != '\0';]])],
+ result = s[13] != '\0';
+ free (s);
+ return result;]])],
[gl_cv_func_strndup_works=yes],
[gl_cv_func_strndup_works=no],
[
main ()
{
/* Check that calloc (0, 0) is not a NULL pointer. */
- if (calloc (0, 0) == NULL)
+ void *p = calloc (0, 0);
+ if (p == NULL)
return 1;
+ free (p);
/* Check that calloc fails when requested to allocate a block of memory
larger than SIZE_MAX bytes. */
- if (calloc ((size_t) -1 / 8 + 1, 8) != NULL)
- return 1;
+ p = calloc ((size_t) -1 / 8 + 1, 8);
+ if (p != NULL)
+ {
+ free (p);
+ return 1;
+ }
return 0;
}
struct locale_dependent_values expected_results;
locale_t mixed1;
locale_t mixed2;
+ locale_t perthread;
/* Set up a locale which is a mix between different system locales. */
setlocale (LC_ALL, "en_US.UTF-8");
ASSERT (mixed1 != NULL);
/* Use a per-thread locale. */
- uselocale (newlocale (LC_ALL_MASK, "es_ES.UTF-8", NULL));
+ perthread = newlocale (LC_ALL_MASK, "es_ES.UTF-8", NULL);
+ uselocale (perthread);
/* Save the locale in a locale_t object again. */
mixed2 = duplocale (LC_GLOBAL_LOCALE);
ASSERT (strcmp (results.time, expected_results.time) == 0);
}
+ setlocale (LC_ALL, "C");
+ freelocale (mixed1);
+ freelocale (mixed2);
+ freelocale (perthread);
return 0;
}
for (i = 0; i < result; i++)
printf ("%d\n", (int) groups[i]);
}
+ free (groups);
return 0;
}
free (line);
/* Test growth of buffer, must not leak. */
- line = malloc (1);
- len = 0;
+ len = 1;
+ line = malloc (len);
result = getline (&line, &len, f);
ASSERT (result == 3);
ASSERT (strcmp (line, "bc\n") == 0);
CK (off_t, offtostr);
CK (uintmax_t, umaxtostr);
CK (intmax_t, imaxtostr);
+ free (b);
return 0;
}
/* snprintf doesn't accept %ju; skip this test. */
+ free (b);
return 77;
}
ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
name = gl_locale_name (LC_MESSAGES, "LC_MESSAGES");
ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
+ uselocale (LC_GLOBAL_LOCALE);
+ freelocale (locale);
}
}
for (i = 0; i < SIZEOF (categories); i++)
{
int category_mask = categories[i].mask;
- locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL);
- if (locale != NULL)
+ locale_t loc = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL);
+ if (loc != NULL)
{
- locale = newlocale (category_mask, "de_DE.UTF-8", locale);
+ locale_t locale = newlocale (category_mask, "de_DE.UTF-8", loc);
if (locale != NULL)
{
unsigned int j;
else
ASSERT (strcmp (name_j, "fr_FR.UTF-8") == 0);
}
+ uselocale (LC_GLOBAL_LOCALE);
+ freelocale (locale);
}
+ freelocale (loc);
}
}
}
ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
name = gl_locale_name_thread (LC_MESSAGES, "LC_MESSAGES");
ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
+ uselocale (LC_GLOBAL_LOCALE);
+ freelocale (locale);
}
}
for (i = 0; i < SIZEOF (categories); i++)
{
int category_mask = categories[i].mask;
- locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL);
- if (locale != NULL)
+ locale_t loc = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL);
+ if (loc != NULL)
{
- locale = newlocale (category_mask, "de_DE.UTF-8", locale);
+ locale_t locale = newlocale (category_mask, "de_DE.UTF-8", loc);
if (locale != NULL)
{
unsigned int j;
else
ASSERT (strcmp (name_j, "fr_FR.UTF-8") == 0);
}
+ uselocale (LC_GLOBAL_LOCALE);
+ freelocale (locale);
}
+ freelocale (loc);
}
}
}
ASSERT (strcmp (unsaved_names[j][i], name) == 0);
}
uselocale (LC_GLOBAL_LOCALE);
+ freelocale (locale);
}
}
/* Verify the unsaved_names are still valid. */
uselocale (locale);
name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
ASSERT (strcmp (name, "C") == 0);
+ uselocale (LC_GLOBAL_LOCALE);
+ freelocale (locale);
}
}
#endif
uselocale (locale);
name = gl_locale_name_environ (LC_MESSAGES, "LC_MESSAGES");
ASSERT (strcmp (name, "C") == 0);
+ uselocale (LC_GLOBAL_LOCALE);
+ freelocale (locale);
}
}
#endif
{
uselocale (locale);
ASSERT (strcmp (gl_locale_name_default (), name) == 0);
+ uselocale (LC_GLOBAL_LOCALE);
+ freelocale (locale);
}
}
#endif
#include <locale.h>
#include <limits.h>
+#include <stdlib.h>
#include <string.h>
#if HAVE_DECL_ALARM
# include <unistd.h>
s = re_compile_pattern (pat, sizeof pat - 1, ®ex);
if (s)
result |= 1;
- else if (re_search (®ex, data, sizeof data - 1,
- 0, sizeof data - 1, ®s)
- != -1)
- result |= 1;
+ else
+ {
+ memset (®s, 0, sizeof regs);
+ if (re_search (®ex, data, sizeof data - 1,
+ 0, sizeof data - 1, ®s)
+ != -1)
+ result |= 1;
+ regfree (®ex);
+ free (regs.start);
+ free (regs.end);
+ }
}
/* Check whether it's really a UTF-8 locale.
result |= 1;
else
{
+ memset (®s, 0, sizeof regs);
i = re_search (®ex, data, sizeof data - 1,
0, sizeof data - 1, 0);
if (i != 0 && i != 21)
result |= 1;
+ regfree (®ex);
+ free (regs.start);
+ free (regs.end);
}
}
if (s)
result |= 2;
/* This should fail, but succeeds for glibc-2.5. */
- else if (re_search (®ex, "a\nb", 3, 0, 3, ®s) != -1)
- result |= 2;
+ else
+ {
+ memset (®s, 0, sizeof regs);
+ if (re_search (®ex, "a\nb", 3, 0, 3, ®s) != -1)
+ result |= 2;
+ regfree (®ex);
+ free (regs.start);
+ free (regs.end);
+ }
/* This regular expression is from Spencer ere test number 75
in grep-2.3. */
s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, ®ex);
/* This should fail with _Invalid character class name_ error. */
if (!s)
- result |= 4;
+ {
+ result |= 4;
+ regfree (®ex);
+ }
/* Ensure that [b-a] is diagnosed as invalid, when
using RE_NO_EMPTY_RANGES. */
memset (®ex, 0, sizeof regex);
s = re_compile_pattern ("a[b-a]", 6, ®ex);
if (s == 0)
- result |= 8;
+ {
+ result |= 8;
+ regfree (®ex);
+ }
/* This should succeed, but does not for glibc-2.1.3. */
memset (®ex, 0, sizeof regex);
s = re_compile_pattern ("{1", 2, ®ex);
if (s)
result |= 8;
+ else
+ regfree (®ex);
/* The following example is derived from a problem report
against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
if (s)
result |= 8;
/* This should match, but does not for glibc-2.2.1. */
- else if (re_match (®ex, "an", 2, 0, ®s) != 2)
- result |= 8;
+ else
+ {
+ memset (®s, 0, sizeof regs);
+ if (re_match (®ex, "an", 2, 0, ®s) != 2)
+ result |= 8;
+ regfree (®ex);
+ free (regs.start);
+ free (regs.end);
+ }
memset (®ex, 0, sizeof regex);
s = re_compile_pattern ("x", 1, ®ex);
if (s)
result |= 8;
/* glibc-2.2.93 does not work with a negative RANGE argument. */
- else if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1)
- result |= 8;
+ else
+ {
+ memset (®s, 0, sizeof regs);
+ if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1)
+ result |= 8;
+ regfree (®ex);
+ free (regs.start);
+ free (regs.end);
+ }
/* The version of regex.c in older versions of gnulib
ignored RE_ICASE. Detect that problem too. */
s = re_compile_pattern ("x", 1, ®ex);
if (s)
result |= 16;
- else if (re_search (®ex, "WXY", 3, 0, 3, ®s) < 0)
- result |= 16;
+ else
+ {
+ memset (®s, 0, sizeof regs);
+ if (re_search (®ex, "WXY", 3, 0, 3, ®s) < 0)
+ result |= 16;
+ regfree (®ex);
+ free (regs.start);
+ free (regs.end);
+ }
/* Catch a bug reported by Vin Shelton in
http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html
s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, ®ex);
if (s)
result |= 32;
+ else
+ regfree (®ex);
/* REG_STARTEND was added to glibc on 2004-01-15.
Reject older versions. */
/* Test that the two results are the same. */
ASSERT (strcmp (name1, name2) == 0);
+ free (name1);
+ free (name2);
return 0;
}
#include <fcntl.h>
#include <errno.h>
#include <stdbool.h>
+#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
ASSERT (unlink (BASE "link2") == 0);
ASSERT (unlink (BASE "link3") == 0);
ASSERT (unlink (BASE "link4") == 0);
+ free (cwd);
return 0;
}