fixinc patch for old glibc strncpy macro

Bruce Korb bkorb@gnu.org
Wed Mar 24 22:26:00 GMT 2010


Looks good to me :)

On Wed, Mar 24, 2010 at 2:54 PM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> This fixincludes patch adds a fix for a strncpy macro definition in
> old versions of glibc's bits/string2.h that causes a warning building
> GDB (see
> <http://sourceware.org/ml/gdb-patches/2009-12/msg00435.html>).  Tested
> with no regressions with cross to i686-pc-linux-gnu using a suitably
> old sysroot.  OK to commit?
>
> fixincludes:
> 2010-03-24  Joseph Myers  <joseph@codesourcery.com>
>
>        * inclhack.def (glibc_strncpy): New fix.
>        * fixincl.x: Regenerate.
>        * tests/base/bits/string2.h: Update.
>
> gcc/testsuite:
> 2010-03-24  Joseph Myers  <joseph@codesourcery.com>
>
>        * gcc.dg/strncpy-fix-1.c: New test.
>
> Index: gcc/testsuite/gcc.dg/strncpy-fix-1.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/strncpy-fix-1.c        (revision 0)
> +++ gcc/testsuite/gcc.dg/strncpy-fix-1.c        (revision 0)
> @@ -0,0 +1,11 @@
> +/* Test that use of strncpy does not result in a "value computed is
> +   not used" warning.  */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -Wall" } */
> +
> +#include <string.h>
> +void
> +f (char *s)
> +{
> +  strncpy (s, "::", 2);
> +}
> Index: fixincludes/tests/base/bits/string2.h
> ===================================================================
> --- fixincludes/tests/base/bits/string2.h       (revision 157705)
> +++ fixincludes/tests/base/bits/string2.h       (working copy)
> @@ -16,3 +16,8 @@
>  #  define __STRING_INLINE extern __inline
>  # endif
>  #endif  /* GLIBC_C99_INLINE_3_CHECK */
> +
> +
> +#if defined( GLIBC_STRNCPY_CHECK )
> +#  define strncpy(dest, src, n) __builtin_strncpy (dest, src, n)
> +#endif  /* GLIBC_STRNCPY_CHECK */
> Index: fixincludes/inclhack.def
> ===================================================================
> --- fixincludes/inclhack.def    (revision 157705)
> +++ fixincludes/inclhack.def    (working copy)
> @@ -1598,6 +1598,28 @@
>  };
>
>
> +/* Some versions of glibc have a version of bits/string2.h that
> +   produces "value computed is not used" warnings from strncpy; fix
> +   this definition by using __builtin_strncpy instead as in newer
> +   versions.  */
> +fix = {
> +    hackname  = glibc_strncpy;
> +    files     = bits/string2.h;
> +    bypass    = "__builtin_strncpy";
> +    c_fix     = format;
> +    c_fix_arg = "#  define strncpy(dest, src, n) __builtin_strncpy (dest, src, n)";
> +    c_fix_arg = "#  define strncpy([^\n]*\\\\\n)*[^\n]*";
> +    test_text = <<-EOT
> +       #  define strncpy(dest, src, n) \
> +         (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n)      \\
> +                         ? (strlen (src) + 1 >= ((size_t) (n))                       \\
> +                            ? (char *) memcpy (dest, src, n)                         \\
> +                            : strncpy (dest, src, n))                                \\
> +                         : strncpy (dest, src, n)))
> +       EOT;
> +
> +};
> +
>  /* glibc's tgmath.h relies on an expression that is not an integer
>    constant expression being treated as it was by GCC 4.4 and
>    earlier.  */
>
> --
> Joseph S. Myers
> joseph@codesourcery.com
>



More information about the Gcc-patches mailing list