[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: snapshots string function warning diff



Did you know there is bug against gcc to warn about some of these 
functions?
http://gcc.gnu.org/PR5694

Thanks,
Andrew Pinski

On Monday, Jun 2, 2003, at 00:12 US/Eastern, Theo de Raadt wrote:

> Some of you might have noticed that the snapshots ship with a change
> that makes the compiler warn for all sprintf and vsprintf calls, but
> also for some strcat and strcpy uses (gcc optimizes some).
>
> This change will most likely not go into 3.4 since it is very
> annoying, but it is a diff that I will continue to compile the tree
> with myself.
>
> Here is that diff.
>
> Index: lib/libc/arch/i386/string/strcat.S
> ===================================================================
> RCS file: /cvs/src/lib/libc/arch/i386/string/strcat.S,v
> retrieving revision 1.2
> diff -u -r1.2 strcat.S
> --- lib/libc/arch/i386/string/strcat.S	19 Aug 1996 08:13:12 -0000	1.2
> +++ lib/libc/arch/i386/string/strcat.S	28 Apr 2003 05:38:02 -0000
> @@ -5,6 +5,11 @@
>
>  #include <machine/asm.h>
>
> +#APP
> +	.stabs "warning: strcat() is almost always misused, consider using 
> strlcat()",30,0,0,0
> +	.stabs "_strcat",1,0,0,0
> +#NO_APP
> +
>  #if defined(LIBC_SCCS)
>  	.text
>  	.asciz "$OpenBSD: strcat.S,v 1.2 1996/08/19 08:13:12 tholo Exp $"
> Index: lib/libc/arch/i386/string/strcpy.S
> ===================================================================
> RCS file: /cvs/src/lib/libc/arch/i386/string/strcpy.S,v
> retrieving revision 1.2
> diff -u -r1.2 strcpy.S
> --- lib/libc/arch/i386/string/strcpy.S	19 Aug 1996 08:13:17 -0000	1.2
> +++ lib/libc/arch/i386/string/strcpy.S	28 Apr 2003 05:37:57 -0000
> @@ -5,6 +5,11 @@
>
>  #include <machine/asm.h>
>
> +#APP
> +	.stabs "warning: strcpy() is almost always misused, consider using 
> strlcpy()",30,0,0,0
> +	.stabs "_strcpy",1,0,0,0
> +#NO_APP
> +
>  #if defined(LIBC_SCCS)
>  	.text
>  	.asciz "$OpenBSD: strcpy.S,v 1.2 1996/08/19 08:13:17 tholo Exp $"
> Index: lib/libc/arch/m68k/string/strcat.S
> ===================================================================
> RCS file: /cvs/src/lib/libc/arch/m68k/string/strcat.S,v
> retrieving revision 1.2
> diff -u -r1.2 strcat.S
> --- lib/libc/arch/m68k/string/strcat.S	19 Aug 1996 08:15:18 -0000	1.2
> +++ lib/libc/arch/m68k/string/strcat.S	17 Apr 2003 03:49:58 -0000
> @@ -37,6 +37,11 @@
>
>  #include "DEFS.h"
>
> +#APP
> +	.stabs "warning: strcat() is almost always misused, consider using 
> strlcat()",30,0,0,0
> +	.stabs "_strcat",1,0,0,0
> +#NO_APP
> +
>  #if defined(LIBC_SCCS)
>  	.text
>  	.asciz "$OpenBSD: strcat.S,v 1.2 1996/08/19 08:15:18 tholo Exp $"
> Index: lib/libc/arch/m68k/string/strcpy.S
> ===================================================================
> RCS file: /cvs/src/lib/libc/arch/m68k/string/strcpy.S,v
> retrieving revision 1.3
> diff -u -r1.3 strcpy.S
> --- lib/libc/arch/m68k/string/strcpy.S	19 Aug 1996 08:15:22 -0000	1.3
> +++ lib/libc/arch/m68k/string/strcpy.S	17 Apr 2003 03:50:07 -0000
> @@ -37,6 +37,11 @@
>
>  #include "DEFS.h"
>
> +#APP
> +	.stabs "warning: strcpy() is almost always misused, consider using 
> strlcpy()",30,0,0,0
> +	.stabs "_strcpy",1,0,0,0
> +#NO_APP
> +
>  #if defined(LIBC_SCCS)
>  	.text
>  	.asciz "$OpenBSD: strcpy.S,v 1.3 1996/08/19 08:15:22 tholo Exp $"
> Index: lib/libc/stdio/sprintf.c
> ===================================================================
> RCS file: /cvs/src/lib/libc/stdio/sprintf.c,v
> retrieving revision 1.5
> diff -u -r1.5 sprintf.c
> --- lib/libc/stdio/sprintf.c	19 Feb 2002 19:39:37 -0000	1.5
> +++ lib/libc/stdio/sprintf.c	16 Apr 2003 02:22:53 -0000
> @@ -43,6 +43,8 @@
>  #include <limits.h>
>  #include "local.h"
>
> +__warn_references(sprintf, "warning: sprintf() is often misused, 
> please use snprintf()");
> +
>  int
>  sprintf(char *str, char const *fmt, ...)
>  {
> Index: lib/libc/stdio/vsprintf.c
> ===================================================================
> RCS file: /cvs/src/lib/libc/stdio/vsprintf.c,v
> retrieving revision 1.4
> diff -u -r1.4 vsprintf.c
> --- lib/libc/stdio/vsprintf.c	9 Jul 2001 06:57:45 -0000	1.4
> +++ lib/libc/stdio/vsprintf.c	7 May 2003 22:36:47 -0000
> @@ -41,6 +41,9 @@
>  #include <stdio.h>
>  #include <limits.h>
>
> +__warn_references(vsprintf,
> +    "warning: vsprintf() is often misused, please use vsnprintf()");
> +
>  int
>  vsprintf(str, fmt, ap)
>  	char *str;
> Index: lib/libc/string/strcat.c
> ===================================================================
> RCS file: /cvs/src/lib/libc/string/strcat.c,v
> retrieving revision 1.4
> diff -u -r1.4 strcat.c
> --- lib/libc/string/strcat.c	19 Aug 1996 08:34:10 -0000	1.4
> +++ lib/libc/string/strcat.c	16 Apr 2003 02:22:44 -0000
> @@ -41,6 +41,8 @@
>  #include <lib/libkern/libkern.h>
>  #endif
>
> +__warn_references(strcat, "warning: strcat() is almost always 
> misused, please use strlcat()");
> +
>  char *
>  strcat(s, append)
>  	register char *s;
> Index: lib/libc/string/strcpy.c
> ===================================================================
> RCS file: /cvs/src/lib/libc/string/strcpy.c,v
> retrieving revision 1.4
> diff -u -r1.4 strcpy.c
> --- lib/libc/string/strcpy.c	19 Aug 1996 08:34:14 -0000	1.4
> +++ lib/libc/string/strcpy.c	16 Apr 2003 02:22:37 -0000
> @@ -41,6 +41,8 @@
>  #include <lib/libkern/libkern.h>
>  #endif
>
> +__warn_references(strcpy, "warning: strcpy() is almost always 
> misused, please use strlcpy()");
> +
>  char *
>  strcpy(to, from)
>  	register char *to;