[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: |
Ben Pfaff |
Subject: |
Re: [PATCH] inttostr.h: add compile-time buffer overrun checks |
Date: |
Mon, 18 Oct 2010 13:15:44 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
Paul Eggert <address@hidden> writes:
> On 10/18/10 04:53, Pádraig Brady wrote:
>
>> /* Like sizeof, except that it treats a variable sized array
>> as a pointer rather than determining the size at runtime. */
>> #define CT_SIZEOF(x) (__builtin_constant_p(sizeof x) ? sizeof x: sizeof
>> (void*))
>
> I don't see how this would work. If x is a variable-sized
> array, CT_SIZEOF(x) is not a constant expression, according
> to the C rules, because for A?B:C to be a constant expression,
> B and C both have to be constant expressions.
One could use __builtin_choose_expr() to avoid that particular problem:
-- Built-in Function: TYPE __builtin_choose_expr (CONST_EXP, EXP1,
EXP2)
You can use the built-in function `__builtin_choose_expr' to
evaluate code depending on the value of a constant expression.
This built-in function returns EXP1 if CONST_EXP, which is a
constant expression that must be able to be determined at compile
time, is nonzero. Otherwise it returns 0.
This built-in function is analogous to the `? :' operator in C,
except that the expression returned has its type unaltered by
promotion rules. Also, the built-in function does not evaluate
the expression that was not chosen. For example, if CONST_EXP
evaluates to true, EXP2 is not evaluated even if it has
side-effects.
--
Ben Pfaff
http://benpfaff.org
- [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, 2010/10/16
- 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 <=
- 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, Pádraig Brady, 2010/10/18
- Re: [PATCH] inttostr.h: add compile-time buffer overrun checks, Jim Meyering, 2010/10/18
- Re: git format-patch, 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, Paul Eggert, 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/19
- Re: [PATCH] inttostr.h: add compile-time buffer overrun checks, Jim Meyering, 2010/10/19
- Re: [PATCH] inttostr.h: add compile-time buffer overrun checks, Paul Eggert, 2010/10/24