Re: [PATCH] staging: wlan-ng: prism2mgmt.c: rewrite flexible array member

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 25, 2023 at 11:27:06AM +0300, Calvince Otieno wrote:
> Declaring zero-length arrays is allowed in GNU C as an extension.
> Although the size of a zero-length array is zero, an array member of
> this kind may increase the size of the enclosing type as a result of
> tail padding. The offset of a zero-length array member from the beginning
> of the enclosing structure is the same as the offset of an array with one
> or more elements of the same type. The alignment of a zero-length array is
> the same as the alignment of its elements.
> 
> Declaring zero-length arrays in other contexts, including as interior
> members of structure objects or as non-member objects, is discouraged.
> Accessing elements of zero-length arrays declared in such contexts is
> undefined and may be diagnosed.
> 
> There are some instances of code in which the sizeof operator is being
> incorrectly/erroneously applied to zero-length arrays and the result
> is zero. Such instances may be hiding some bugs.
> 
> This issue was found with the help of Coccinelle.
> 
> [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
> 
> Signed-off-by: Calvince Otieno <calvncce@xxxxxxxxx>
> ---
>  drivers/staging/wlan-ng/p80211metastruct.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/wlan-ng/p80211metastruct.h b/drivers/staging/wlan-ng/p80211metastruct.h
> index a52217c9b953..c8b73c867391 100644
> --- a/drivers/staging/wlan-ng/p80211metastruct.h
> +++ b/drivers/staging/wlan-ng/p80211metastruct.h
> @@ -71,7 +71,6 @@ struct p80211msg_dot11req_scan_results {
>  	struct p80211item_uint32 signal;
>  	struct p80211item_uint32 noise;
>  	struct p80211item_pstr6 bssid;
> -	u8 pad_3C[1];
                  ^
This is not a zero.  This is a one.  It's put there very deliberately to
"pad" the struct.

regards,
dan carpenter
> 




[Index of Archives]     [Linux Driver Development]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux