outreachy.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Calvince Otieno <calvncce@gmail.com>
To: gustavo@embeddedor.com, outreachy@lists.linux.dev
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.or,
	Julia Lawall <julia.lawall@inria.fr>,
	Deepak <dvarma04@hotmail.com>,
	Calvince Otieno <calvncce@gmail.com>
Subject: [PATCH] staging: wlan-ng: prism2mgmt.c: rewrite flexible array member
Date: Wed, 25 Oct 2023 11:27:06 +0300	[thread overview]
Message-ID: <ZTjRWkqXeoS74E52@lab-ubuntu> (raw)

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@gmail.com>
---
 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];
 	struct p80211item_pstr32 ssid;
 	u8 pad_4D[3];
 	struct p80211item_uint32 bsstype;
@@ -95,6 +94,7 @@ struct p80211msg_dot11req_scan_results {
 	struct p80211item_uint32 capinfo;
 	struct p80211item_uint32 basicrate[8];
 	struct p80211item_uint32 supprate[8];
+	u8 pad_3C[];
 } __packed;
 
 struct p80211msg_dot11req_start {
-- 
2.34.1


             reply	other threads:[~2023-10-25  8:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-25  8:27 Calvince Otieno [this message]
2023-10-25  8:31 ` [PATCH] staging: wlan-ng: prism2mgmt.c: rewrite flexible array member Dan Carpenter
2023-10-25  8:35 ` Greg Kroah-Hartman
2023-10-25  8:58   ` Calvince Otieno
2023-10-25  9:05     ` Greg Kroah-Hartman
2023-10-25  9:21       ` Calvince Otieno
2023-10-25  9:48         ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZTjRWkqXeoS74E52@lab-ubuntu \
    --to=calvncce@gmail.com \
    --cc=dvarma04@hotmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavo@embeddedor.com \
    --cc=julia.lawall@inria.fr \
    --cc=linux-kernel@vger.kernel.or \
    --cc=linux-staging@lists.linux.dev \
    --cc=outreachy@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).