This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC] Avoid spurious isolate-erroneous-paths failures
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Mon, 18 Nov 2013 16:39:02 +0100
- Subject: [RFC] Avoid spurious isolate-erroneous-paths failures
- Authentication-results: sourceware.org; auth=none
Hi,
a gcc isolate-erroneous-paths switch causes trapping of
memset (NULL, 0, 0), see
http://gcc.gnu.org/ml/gcc/2013-11/msg00345.html
This could give a isolate-erroneous-paths bad reputation as it will
cause more spurious failures than real problems.
One way how to fix this would be drop nonnull attribute from mem* and
strn* function as patch below does.
On other hand a c standard says that passes pointers must be always
valid. String routines now do extra check for n==0 to avoid
dereferencing pointer. By dropping this check a call could be a cycle
faster.
diff --git a/string/string.h b/string/string.h
index ecc3fef..68e19c6 100644
--- a/string/string.h
+++ b/string/string.h
@@ -40,7 +40,7 @@ __BEGIN_DECLS
__BEGIN_NAMESPACE_STD
/* Copy N bytes of SRC to DEST. */
extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
- size_t __n) __THROW __nonnull ((1, 2));
+ size_t __n) __THROW;
/* Copy N bytes of SRC to DEST, guaranteeing
correct behavior for overlapping strings. */
extern void *memmove (void *__dest, const void *__src, size_t __n)
@@ -53,26 +53,26 @@ __END_NAMESPACE_STD
#if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN
extern void *memccpy (void *__restrict __dest, const void *__restrict __src,
int __c, size_t __n)
- __THROW __nonnull ((1, 2));
+ __THROW;
#endif /* SVID. */
__BEGIN_NAMESPACE_STD
/* Set N bytes of S to C. */
-extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1));
+extern void *memset (void *__s, int __c, size_t __n) __THROW;
/* Compare N bytes of S1 and S2. */
extern int memcmp (const void *__s1, const void *__s2, size_t __n)
- __THROW __attribute_pure__ __nonnull ((1, 2));
+ __THROW __attribute_pure__;
/* Search N bytes of S for C. */
#ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
extern "C++"
{
extern void *memchr (void *__s, int __c, size_t __n)
- __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1));
+ __THROW __asm ("memchr") __attribute_pure__;
extern const void *memchr (const void *__s, int __c, size_t __n)
- __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1));
+ __THROW __asm ("memchr") __attribute_pure__;
# ifdef __OPTIMIZE__
__extern_always_inline void *
@@ -90,7 +90,7 @@ memchr (const void *__s, int __c, size_t __n) __THROW
}
#else
extern void *memchr (const void *__s, int __c, size_t __n)
- __THROW __attribute_pure__ __nonnull ((1));
+ __THROW __attribute_pure__;
#endif
__END_NAMESPACE_STD
@@ -110,12 +110,12 @@ extern void *rawmemchr (const void *__s, int __c)
/* Search N bytes of S for the final occurrence of C. */
# ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
extern "C++" void *memrchr (void *__s, int __c, size_t __n)
- __THROW __asm ("memrchr") __attribute_pure__ __nonnull ((1));
+ __THROW __asm ("memrchr") __attribute_pure__;
extern "C++" const void *memrchr (const void *__s, int __c, size_t __n)
- __THROW __asm ("memrchr") __attribute_pure__ __nonnull ((1));
+ __THROW __asm ("memrchr") __attribute_pure__;
# else
extern void *memrchr (const void *__s, int __c, size_t __n)
- __THROW __attribute_pure__ __nonnull ((1));
+ __THROW __attribute_pure__;
# endif
#endif
@@ -134,14 +134,14 @@ extern char *strcat (char *__restrict __dest, const char *__restrict __src)
__THROW __nonnull ((1, 2));
/* Append no more than N characters from SRC onto DEST. */
extern char *strncat (char *__restrict __dest, const char *__restrict __src,
- size_t __n) __THROW __nonnull ((1, 2));
+ size_t __n) __THROW __nonnull ((1));
/* Compare S1 and S2. */
extern int strcmp (const char *__s1, const char *__s2)
__THROW __attribute_pure__ __nonnull ((1, 2));
/* Compare N characters of S1 and S2. */
extern int strncmp (const char *__s1, const char *__s2, size_t __n)
- __THROW __attribute_pure__ __nonnull ((1, 2));
+ __THROW __attribute_pure__;
/* Compare the collated forms of S1 and S2. */
extern int strcoll (const char *__s1, const char *__s2)
@@ -163,7 +163,7 @@ extern int strcoll_l (const char *__s1, const char *__s2, __locale_t __l)
__THROW __attribute_pure__ __nonnull ((1, 2, 3));
/* Put a transformation of SRC into no more than N bytes of DEST. */
extern size_t strxfrm_l (char *__dest, const char *__src, size_t __n,
- __locale_t __l) __THROW __nonnull ((2, 4));
+ __locale_t __l) __THROW __nonnull ((4));
#endif
#if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED \
@@ -178,7 +178,7 @@ extern char *strdup (const char *__s)
appears before STRING[N]. */
#if defined __USE_XOPEN2K8
extern char *strndup (const char *__string, size_t __n)
- __THROW __attribute_malloc__ __nonnull ((1));
+ __THROW __attribute_malloc__;
#endif
#if defined __USE_GNU && defined __GNUC__
@@ -377,16 +377,16 @@ extern char *strcasestr (const char *__haystack, const char *__needle)
HAYSTACK is HAYSTACKLEN bytes long. */
extern void *memmem (const void *__haystack, size_t __haystacklen,
const void *__needle, size_t __needlelen)
- __THROW __attribute_pure__ __nonnull ((1, 3));
+ __THROW __attribute_pure__;
/* Copy N bytes of SRC to DEST, return pointer to bytes after the
last written byte. */
extern void *__mempcpy (void *__restrict __dest,
const void *__restrict __src, size_t __n)
- __THROW __nonnull ((1, 2));
+ __THROW;
extern void *mempcpy (void *__restrict __dest,
const void *__restrict __src, size_t __n)
- __THROW __nonnull ((1, 2));
+ __THROW;
#endif
@@ -400,7 +400,7 @@ __END_NAMESPACE_STD
/* Find the length of STRING, but scan at most MAXLEN characters.
If no '\0' terminator is found in that many characters, return MAXLEN. */
extern size_t strnlen (const char *__string, size_t __maxlen)
- __THROW __attribute_pure__ __nonnull ((1));
+ __THROW __attribute_pure__;
#endif
@@ -444,7 +444,7 @@ extern char *strerror_l (int __errnum, __locale_t __l) __THROW;
/* We define this function always since `bzero' is sometimes needed when
the namespace rules does not allow this. */
-extern void __bzero (void *__s, size_t __n) __THROW __nonnull ((1));
+extern void __bzero (void *__s, size_t __n) __THROW;
#ifdef __USE_BSD
/* Copy N bytes of SRC to DEST (like memmove, but args reversed). */
@@ -452,11 +452,11 @@ extern void bcopy (const void *__src, void *__dest, size_t __n)
__THROW __nonnull ((1, 2));
/* Set N bytes of S to 0. */
-extern void bzero (void *__s, size_t __n) __THROW __nonnull ((1));
+extern void bzero (void *__s, size_t __n) __THROW;
/* Compare N bytes of S1 and S2 (same as memcmp). */
extern int bcmp (const void *__s1, const void *__s2, size_t __n)
- __THROW __attribute_pure__ __nonnull ((1, 2));
+ __THROW __attribute_pure__;
/* Find the first occurrence of C in S (same as strchr). */
# ifdef __CORRECT_ISO_CPP_STRING_H_PROTO