diff options
Diffstat (limited to 'string/bits/string3.h')
-rw-r--r-- | string/bits/string3.h | 17 |
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) |