Re: [Qemu-devel] [PATCH v3 4/4] ARRAY_SIZE: check that argument is an array

2017-01-20 Thread Paolo Bonzini
On 20/01/2017 08:34, Markus Armbruster wrote: > Eric Blake writes: > >> On 01/19/2017 04:11 PM, Michael S. Tsirkin wrote: >> > +#define QEMU_IS_ARRAY(x) (!__builtin_types_compatible_p(typeof(x), \ > +typeof(&(x)[0]))) > #ifnde

Re: [Qemu-devel] [PATCH v3 4/4] ARRAY_SIZE: check that argument is an array

2017-01-19 Thread Markus Armbruster
Eric Blake writes: > On 01/19/2017 04:11 PM, Michael S. Tsirkin wrote: > +#define QEMU_IS_ARRAY(x) (!__builtin_types_compatible_p(typeof(x), \ +typeof(&(x)[0]))) #ifndef ARRAY_SIZE -#define ARRAY_SIZE(x) (sizeof(x) / siz

Re: [Qemu-devel] [PATCH v3 4/4] ARRAY_SIZE: check that argument is an array

2017-01-19 Thread Eric Blake
On 01/19/2017 04:11 PM, Michael S. Tsirkin wrote: >>> +#define QEMU_IS_ARRAY(x) (!__builtin_types_compatible_p(typeof(x), \ >>> +typeof(&(x)[0]))) >>> #ifndef ARRAY_SIZE >>> -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) >>> +#define AR

Re: [Qemu-devel] [PATCH v3 4/4] ARRAY_SIZE: check that argument is an array

2017-01-19 Thread Michael S. Tsirkin
On Thu, Jan 19, 2017 at 03:59:33PM -0600, Eric Blake wrote: > On 01/19/2017 03:07 PM, Michael S. Tsirkin wrote: > > It's a familiar pattern: some code uses ARRAY_SIZE, then refactoring > > changes the argument from an array to a pointer to a dynamically > > allocated buffer. Code keeps compiling b

Re: [Qemu-devel] [PATCH v3 4/4] ARRAY_SIZE: check that argument is an array

2017-01-19 Thread Eric Blake
On 01/19/2017 03:07 PM, Michael S. Tsirkin wrote: > It's a familiar pattern: some code uses ARRAY_SIZE, then refactoring > changes the argument from an array to a pointer to a dynamically > allocated buffer. Code keeps compiling but any ARRAY_SIZE calls now > return the size of the pointer divided

[Qemu-devel] [PATCH v3 4/4] ARRAY_SIZE: check that argument is an array

2017-01-19 Thread Michael S. Tsirkin
It's a familiar pattern: some code uses ARRAY_SIZE, then refactoring changes the argument from an array to a pointer to a dynamically allocated buffer. Code keeps compiling but any ARRAY_SIZE calls now return the size of the pointer divided by element size. Let's add build time checks to ARRAY_SI