Re: [PATCH 7/7] asm-generic: suppress sparse warning in ioctl.h

From: Al Viro
Date: Thu Apr 03 2008 - 22:00:29 EST


On Fri, Apr 04, 2008 at 02:19:51AM +0100, Al Viro wrote:
> * no functions returning variably-modified type.

Note: *pointer* to function returning a variably-modified type is possible,
is variably-modified itself and as such can appear only in function and
the same "compiler will consider VLA compatible with any array that has
as compatible element, but if the size doesn't match it's on your head"
applies. IOW,

int a[2][2] = {{1, 2}, {3, 4}};

int (*f(void))[2] /* return a pointer to two-element array of int */
{
return &a[0];
}

int h(int n)
{
/* pointer to function that returns a pointer to n-element VLA of int */
int (*(*p)(void))[n];
/* OK if n is 2, undefined otherwise */
p = f;
return p()[1][1];
}

is fine and h(2) will give you 4, but if you ever do e.g. h(1), you are in
nasal daemon country. In reality h(1) will _probably_ give a[1][0], but
compiler has every right to silently produce a binary that'll wipe your disk
or do the same itself...
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/