Date: Mon, 27 Nov 2000 17:24:42 +0100 (CET) From: Alexander Leidinger <Alexander@Leidinger.net> To: kris@FreeBSD.ORG Cc: audit@FreeBSD.ORG Subject: Re: gcc __attributes for format strings Message-ID: <200011271624.eARGOir89679@Magelan.Leidinger.net> In-Reply-To: <20001126222048.A46809@citusc17.usc.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
On 26 Nov, Kris Kennaway wrote:
> Okay, looks like we can play with some gcc attributes to flag things
> as format strings. For example:
>
> Index: create_chunk.c
> ===================================================================
> RCS file: /mnt/ncvs/src/lib/libdisk/create_chunk.c,v
> retrieving revision 1.54
> diff -u -r1.54 create_chunk.c
> --- create_chunk.c 2000/11/06 23:15:01 1.54
> +++ create_chunk.c 2000/11/27 06:14:00
> @@ -28,6 +28,8 @@
> #include <pwd.h>
> #include "libdisk.h"
>
> +static void msgDebug(char *, ...) __printf0like(1,0);
> +
> /* Clone these two from sysinstall because we need our own copies
> * due to link order problems with `crunch'. Feh!
> */
>
> __printf0like(a,b) says "treat argument 'a' as a printf format string
> which may be null, and arguments starting with 'b' are the arguments
> to the format string". b=0 is for the case of a varargs function like
> above.
From gcc.info (on -current):
---snip---
`format (ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK)'
The `format' attribute specifies that a function takes `printf',
`scanf', or `strftime' style arguments which should be type-checked
against a format string. For example, the declaration:
extern int
my_printf (void *my_object, const char *my_format, ...)
__attribute__ ((format (printf, 2, 3)));
causes the compiler to check the arguments in calls to `my_printf'
for consistency with the `printf' style format string argument
`my_format'.
[...]
---snip---
A search in gcc.info for printflike didn't show a match.
Bye,
Alexander.
--
Reboot America.
http://www.Leidinger.net Alexander @ Leidinger.net
GPG fingerprint = 7423 F3E6 3A7E B334 A9CC B10A 1F5F 130A A638 6E7E
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200011271624.eARGOir89679>
