Thread (37 messages) 37 messages, 9 authors, 2018-10-09

Re: [PATCH 04/11] UAPI: bcache: Fix use of embedded flexible array

From: Jan Engelhardt <hidden>
Date: 2018-10-02 14:53:01
Also in: linux-api, linux-bcache, linux-kbuild

On Wed, 05 Sep 2018 16:55:03 +0100, David Howells wrote:
The bkey struct defined by bcache is embedded in the jset struct. However,
this is illegal in C++ as there's a "flexible array" at the end of the struct.
Change this to be a 0-length struct instead.

-	__u64	ptr[];
+	__u64	ptr[0];
As per the C++ standard, it is _also_ illegal to declare an array of size zero.

"""it [the array size expression] shall be a converted constant expression of
type std::size_t and its value shall be greater than zero."""
—http://eel.is/c++draft/dcl.array

That makes both "__u64 ptr[]" and "__u64 ptr[0]" *implementation-specific
extensions*.


3rd party tooling (concerns both C and C++):

Coverity Scan (IIRC) treats "__u64 ptr[0]" as an array of "definitely-zero"
size. Writing to any element will outright flag an out-of-bounds violation.
That is sensible, since only "ptr[]" was standardized.


Conclusion:

So please, do never use __u64 ptr[0].
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help