[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] inttostr.h: add compile-time buffer overrun checks
From: |
Bruno Haible |
Subject: |
Re: [PATCH] inttostr.h: add compile-time buffer overrun checks |
Date: |
Sun, 17 Oct 2010 01:51:37 +0200 |
User-agent: |
KMail/1.9.9 |
Hi Jim,
> +# define inttostr(n, s) \
> + ((void) verify_true (sizeof (s) == sizeof (void *) \
> + || INT_BUFSIZE_BOUND (int) <= sizeof (s)), \
> + (inttostr) (n, s))
Nice and clever trick.
Unfortunately, it does not work for variable-length arrays, which are allowed
in C99 and C++.
Test case:
void foo (int n)
{
char buf[10 + (n < 0) + 1];
char *result = inttostr (n, buf);
}
Yields:
foo.c: In function ‘foo’:
foo.c:38: error: bit-field ‘verify_error_if_negative_size__’ width not an
integer constant
How to fix this? I tried __builtin_constant_p and __builtin_choose_expr, but
haven't found the trick.
Bruno
- [PATCH] inttostr.h: add compile-time buffer overrun checks, Jim Meyering, 2010/10/16
- Re: [PATCH] inttostr.h: add compile-time buffer overrun checks,
Bruno Haible <=
- Re: [PATCH] inttostr.h: add compile-time buffer overrun checks, Jim Meyering, 2010/10/17
- Re: [PATCH] inttostr.h: add compile-time buffer overrun checks, Bruno Haible, 2010/10/17
- Re: [PATCH] inttostr.h: add compile-time buffer overrun checks, Jim Meyering, 2010/10/17
- Re: [PATCH] inttostr.h: add compile-time buffer overrun checks, Bruno Haible, 2010/10/17
- Re: [PATCH] inttostr.h: add compile-time buffer overrun checks, Pádraig Brady, 2010/10/18
- Re: [PATCH] inttostr.h: add compile-time buffer overrun checks, Paolo Bonzini, 2010/10/18
- Re: [PATCH] inttostr.h: add compile-time buffer overrun checks, Bruno Haible, 2010/10/18
- Re: [PATCH] inttostr.h: add compile-time buffer overrun checks, Paul Eggert, 2010/10/18
- Re: [PATCH] inttostr.h: add compile-time buffer overrun checks, Ben Pfaff, 2010/10/18
- Re: [PATCH] inttostr.h: add compile-time buffer overrun checks, Pádraig Brady, 2010/10/18