summaryrefslogtreecommitdiff
path: root/string
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2005-03-03 13:34:35 +0000
committerJakub Jelinek <jakub@redhat.com>2005-03-03 13:34:35 +0000
commitd0fec8d06cc2234c8114b51f630466eff9d5f841 (patch)
tree223a7fdae69137bd5670e59249442bc6a2db1ad1 /string
parent00e4559b612f179492ff3721f86c92498894432f (diff)
Updated to fedora-glibc-20050302T1820
Diffstat (limited to 'string')
-rw-r--r--string/bits/string3.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/string/bits/string3.h b/string/bits/string3.h
index 87cbe35bb1..6c027c23a0 100644
--- a/string/bits/string3.h
+++ b/string/bits/string3.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2004, 2005 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
@@ -80,10 +80,19 @@ __mempcpy_ichk (void *__restrict __dest, const void *__restrict __src,
#endif
+/* The first two tests here help to catch a somewhat common problem
+ where the second and third parameter are transposed. This is
+ especially problematic if the intended fill value is zero. In this
+ case no work is done at all. We detect these problems by referring
+ non-existing functions. */
+__warndecl (__warn_memset_zero_len,
+ "memset used with constant zero length parameter; this could be due to transposed parameters");
#define memset(dest, ch, len) \
- ((__bos0 (dest) != (size_t) -1) \
- ? __builtin___memset_chk (dest, ch, len, __bos0 (dest)) \
- : __memset_ichk (dest, ch, len))
+ (__builtin_constant_p (len) && (len) == 0 \
+ ? (__warn_memset_zero_len (), (void) (ch), (void) (len), (void *) (dest)) \
+ : ((__bos0 (dest) != (size_t) -1) \
+ ? __builtin___memset_chk (dest, ch, len, __bos0 (dest)) \
+ : __memset_ichk (dest, ch, len)))
static __inline__ void *
__attribute__ ((__always_inline__))
__memset_ichk (void *__dest, int __ch, size_t __len)