This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Another glibc fixincl-hack
- From: Bruce Korb <bkorb at gnu dot org>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 02 Dec 2006 09:40:20 -0800
- Subject: Another glibc fixincl-hack
- Reply-to: bkorb at gnu dot org
glibc has this in bits/string2.h. The issue with it is that
there are platforms where sizeof(int) != sizeof(size_t).
The easiest solution is:
s/ calloc (1, 1)/ calloc ((size_t)1, (size_t)1)/
I will supply a patch shortly, unless someone takes issue.
Thanks - Bruce
/* We need the memory allocation functions for inline strdup().
Referring to stdlib.h (even minimally) is not allowed
in any of the tight standards compliant modes. */
#ifdef __USE_MISC
# if !defined _HAVE_STRING_ARCH_strdup || !defined _HAVE_STRING_ARCH_strndup
# define __need_malloc_and_calloc
# include <stdlib.h>
# endif
# ifndef _HAVE_STRING_ARCH_strdup
extern char *__strdup (__const char *__string) __THROW __attribute_malloc__;
# define __strdup(s) \
(__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s)
\
? (((__const 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)
# endif
# endif
# ifndef _HAVE_STRING_ARCH_strndup
extern char *__strndup (__const char *__string, size_t __n)
__THROW __attribute_malloc__;
# define __strndup(s, n) \
(__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s)
\
? (((__const 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 + 1; \
__retval = (char *) malloc (__len); \
if (__retval != NULL) \
{ \
__retval[__len - 1] = '\0'; \
__retval = (char *) memcpy (__retval, s, \
__len - 1); \
} \
__retval; })) \
: __strndup (s, n)))
# ifdef __USE_GNU
# define strndup(s, n) __strndup (s, n)
# endif
# endif
#endif /* Use misc. or use GNU. */