From 7551a1e5100c596793fa182cd26346ff971d3a4f Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 18 Mar 1998 17:57:13 +0000 Subject: [PATCH] Update. 1998-03-18 Andreas Jaeger * manual/memory.texi (Heap Consistency Checking): Document MALLOC_CHECK_. Based on a text by Wolfram Gloger. 1998-03-18 17:11 Zack Weinberg * manual/Makefile: Add missing rules. 1998-03-18 Ulrich Drepper * timezone/Makefile (generated): Define to remove all stamp files. * sysdeps/generic/strsep.c: Also undefine __strsep. * string/strdup.c: Undefine __strdup and strdup first. * string/strndup.c: Likewise. * string/bits/string2.h: Correct strtok_r and strsep. Add strndup optimization. * sysdeps/generic/strsep.c: Little optimization. --- ChangeLog | 23 +++++++++++++++++++ FAQ.in | 16 +++++++------- manual/Makefile | 8 ++++++- manual/memory.texi | 14 ++++++++++++ string/bits/string2.h | 57 +++++++++++++++++++++++++++++++++++++----------- string/strdup.c | 5 ++++- string/strndup.c | 5 ++++- sysdeps/generic/strsep.c | 3 ++- timezone/Makefile | 1 + 9 files changed, 107 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6eb771e..e01da98 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +1998-03-18 Andreas Jaeger + + * manual/memory.texi (Heap Consistency Checking): Document + MALLOC_CHECK_. Based on a text by Wolfram Gloger. + +1998-03-18 17:11 Zack Weinberg + + * manual/Makefile: Add missing rules. + +1998-03-18 Ulrich Drepper + + * timezone/Makefile (generated): Define to remove all stamp files. + + * sysdeps/generic/strsep.c: Also undefine __strsep. + + * string/strdup.c: Undefine __strdup and strdup first. + * string/strndup.c: Likewise. + + * string/bits/string2.h: Correct strtok_r and strsep. + Add strndup optimization. + + * sysdeps/generic/strsep.c: Little optimization. + 1998-03-18 14:25 Ulrich Drepper * string/bits/string2.h: Add optimization for strdup. diff --git a/FAQ.in b/FAQ.in index 97e5525..bbfbe98 100644 --- a/FAQ.in +++ b/FAQ.in @@ -55,9 +55,9 @@ and the many mirror sites. ftp.gnu.org is always overloaded, so try to find a local mirror first. You always should try to use the latest official release. Older -versions may not have all the features GNU libc requires. On most -supported platforms (for powerpc see question ?powerpc), 2.7.2.3 is -the earliest version that works at all. +versions may not have all the features GNU libc requires. The current +releases of egcs (1.0.2) and GNU CC (2.8.1) should work with the GNU C +library (for powerpc see question ?powerpc). ?? When I try to compile glibc I get only error messages. What's wrong? @@ -83,7 +83,7 @@ Always get the newest release of GNU binutils available. Older releases are known to have bugs that prevent a successful compilation. {ZW} As of release 2.1 a linker supporting symbol versions is -required. For Linux, get binutils-2.8.1.0.17 or later. Other systems +required. For Linux, get binutils-2.8.1.0.23 or later. Other systems may have native linker support, but it's moot right now, because glibc has not been ported to them. @@ -481,9 +481,9 @@ GROUP ( libc.so.6 ld-linux.so.2 libc.a ) ?? How can I compile gcc 2.7.2.1 from the gcc source code using glibc 2.x? -{AJ} There's only correct support for glibc 2.0.x in gcc 2.7.2.3 -or later. You should get at least gcc 2.7.2.3. All previous versions -had problems with glibc support. +{AJ} There's only correct support for glibc 2.0.x in gcc 2.7.2.3 or +later. But you should get at least gcc 2.8.1 or egcs 1.0.2 (or later +versions) instead. ?? The `gencat' utility cannot process the catalog sources which were used on my Linux libc5 based system. Why? @@ -620,7 +620,7 @@ problem. ?? What do I need for C++ development? -{HJ,AJ} You need either egcs 1.0.1 or gcc-2.8.1 with libstdc++ +{HJ,AJ} You need either egcs 1.0.2 or gcc-2.8.1 with libstdc++ 2.8.1 (or more recent versions). libg++ 2.7.2 (and the Linux Versions 2.7.2.x) doesn't work very well with the GNU C library due to vtable thunks. If you're upgrading from glibc 2.0.x to 2.1 you have to recompile diff --git a/manual/Makefile b/manual/Makefile index c528493..c56dd32 100644 --- a/manual/Makefile +++ b/manual/Makefile @@ -69,6 +69,12 @@ endef libc.dvi libc.info: $(chapters) summary.texi $(chapters-incl) libc.dvi: texinfo.tex +%.info: %.texinfo + $(MAKEINFO) $< + +%.dvi: %.texinfo + $(TEXI2DVI) $< + # Generate the summary from the Texinfo source files for each chapter. summary.texi: stamp-summary ; stamp-summary: summary.awk $(chapters) $(chapters-incl) @@ -81,7 +87,7 @@ stamp-summary: summary.awk $(chapters) $(chapters-incl) # Generate a file which can be added to the `dir' content to provide direct # access to the documentation of the function, variables, and other # definitions. -dir-add.texi: xtract-typefun.awk $(chapters) $(chapters-incl) +dir-add.texinfo: xtract-typefun.awk $(chapters) $(chapters-incl) (echo "@dircategory GNU C library functions"; \ echo "@direntry"; \ $(GAWK) -f $^ | sort; \ diff --git a/manual/memory.texi b/manual/memory.texi index 4e42b47..09147bc 100644 --- a/manual/memory.texi +++ b/manual/memory.texi @@ -611,6 +611,20 @@ The block was already freed. @end table @end deftp +Another possibility to check for and guard against bugs in the use of +@code{malloc}, @code{realloc} and @code{free} is to set the environment +variable @code{MALLOC_CHECK_}. When @code{MALLOC_CHECK_} is set, a +special (less efficient) implementation is used which is designed to be +tolerant against simple errors, such as double calls of @code{free} with +the same argument, or overruns of a single byte (off-by-one bugs). Not +all such errors can be proteced against, however, and memory leaks can +result. If @code{MALLOC_CHECK_} is set to @code{0}, any detected heap +corruption is silently ignored; if set to @code{1}, a diagnostic is +printed on @code{stderr}; if set to @code{2}, @code{abort} is called +immediately. This can be useful because otherwise a crash may happen +much later, and the true cause for the problem is then very hard to +track down. + @node Hooks for Malloc @subsection Storage Allocation Hooks @cindex allocation hooks, for @code{malloc} diff --git a/string/bits/string2.h b/string/bits/string2.h index 4b8f161..a84cede 100644 --- a/string/bits/string2.h +++ b/string/bits/string2.h @@ -710,8 +710,8 @@ strnlen (__const char *__string, size_t __maxlen) ? (((__const unsigned char *) (sep))[0] != '\0' \ && ((__const unsigned char *) (sep))[1] == '\0' \ ? __strtok_r_1c (s, ((__const char *) (sep))[0], nextp) \ - : strtok_r (s, sep, nextp)) \ - : strtok_r (s, sep, nextp))) + : __strtok_r (s, sep, nextp)) \ + : __strtok_r (s, sep, nextp))) __STRING_INLINE char *__strtok_r_1c (char *__s, char __sep, char **__nextp); __STRING_INLINE char * @@ -740,7 +740,7 @@ __strtok_r_1c (char *__s, char __sep, char **__nextp) return __result; } # if defined __USE_POSIX || defined __USE_MISC -# define strtok_r(s, sep, nextp) __strtok_r (s, sep, nextp) +# define strtok_r(s, sep, nextp) __strtok_r ((s), (sep), (nextp)) # endif #endif @@ -845,7 +845,7 @@ __strsep_g (char **__s, __const char *__reject) return __retval; } # ifdef __USE_BSD -# define strsep(s, reject) __strsep (s, reject) +# define strsep(s, reject) __strsep ((s), (reject)) # endif #endif @@ -857,15 +857,15 @@ __strsep_g (char **__s, __const char *__reject) # include # define __strdup(s) \ - (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) - ? (((__const unsigned char *) (s))[0] == '\0' - ? return (char *) calloc (1, 1); - : ({ size_t len = strlen (s) + 1; - char *retval = (char *) malloc (len); - if (retval != NULL) - retval = (char *) memcpy (retval, s, len); - retval; })) - : strdup (s))) + (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \ + ? (((__const unsigned char *) (s))[0] == '\0' \ + ? (char *) calloc (1, 1) \ + : ({ size_t __len = strlen (s) + 1; \ + char *__retval = (char *) malloc (__len); \ + if (__retval != NULL) \ + __retval = (char *) memcpy (__retval, s, __len); \ + __retval; })) \ + : __strdup (s))) # if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED # define strdup(s) __strdup (s) @@ -873,6 +873,37 @@ __strsep_g (char **__s, __const char *__reject) #endif +#if !defined _HAVE_STRING_ARCH_strndup && !defined __STRICT_ANSI__ + +/* We need the memory allocation functions. Including this header is + not allowed. */ +# include + +# define __strndup(s, n) \ + (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \ + ? (((__const unsigned char *) (s))[0] == '\0' \ + ? (char *) calloc (1, 1) \ + : ({ size_t __len = strlen (s) + 1; \ + size_t __n = (n); \ + char *__retval; \ + if (__n < __len) \ + __len = __n; \ + __retval = (char *) malloc (__len); \ + if (__retval != NULL) \ + { \ + __retval[__len - 1] = '\0'; \ + __retval = (char *) memcpy (__retval, s, \ + __len - 1); \ + } \ + __retval; })) \ + : __strndup ((s), (n)))) + +# ifdef __GNU_SOURCE +# define strndup(s, n) __strndup ((s), (n)) +# endif +#endif + + #undef __STRING_INLINE #endif /* No string inlines. */ diff --git a/string/strdup.c b/string/strdup.c index be3883f..2e0852c 100644 --- a/string/strdup.c +++ b/string/strdup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1996, 1997, 1998 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -28,6 +28,9 @@ char *malloc (); char *memcpy (); #endif +#undef __strdup +#undef strdup + #ifndef weak_alias # define __strdup strdup #endif diff --git a/string/strndup.c b/string/strndup.c index cd971e1..3f53442 100644 --- a/string/strndup.c +++ b/string/strndup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. +/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -30,6 +30,9 @@ char *malloc (); #endif +#undef __strndup +#undef strndup + #ifndef weak_alias # define __strndup strndup #endif diff --git a/sysdeps/generic/strsep.c b/sysdeps/generic/strsep.c index 1c20eb0..7ca44f3 100644 --- a/sysdeps/generic/strsep.c +++ b/sysdeps/generic/strsep.c @@ -18,6 +18,7 @@ #include +#undef __strsep #undef strsep char * @@ -43,7 +44,7 @@ __strsep (char **stringp, const char *delim) if (*begin == ch) end = begin; else - end = strchr (begin, delim[0]); + end = strchr (begin + 1, ch); } } else diff --git a/timezone/Makefile b/timezone/Makefile index f089b94..fc8b598 100644 --- a/timezone/Makefile +++ b/timezone/Makefile @@ -39,6 +39,7 @@ tzfiles := $(tzbases) $(tzlinks) # northamerica. distribute += $(tzfiles) leapseconds pacificnew simplebackw +generated := $(addprefix z.,$(tzfiles)) install-sbin := zic zdump generated-dirs = testdata -- 2.7.4