[igt-dev] [PATCH i-g-t] lib/igt_edid: Fix an array bounds warning in cea_vsdb_get_hdmi_default()

Jeremy Cline jcline at redhat.com
Thu Feb 18 18:55:08 UTC 2021


On Fedora 34 with GCC 11, the IGT build fails with "error: array
subscript ‘struct hdmi_vsdb[0]’ is partly outside array bounds of
‘char[7]’ [-Werror=array-bounds]". This is caused by not allocating the
full size of the struct cea_vsdb, and even though the final field is not
accessed, this is confusing to both GCC and yours truly.

Fix this warning by allocating enough memory for the entire struct,
which is 8 bytes rather than the current allocation of 7 bytes. Continue
to report the size to callers as 7 bytes.

Signed-off-by: Jeremy Cline <jcline at redhat.com>
---
 lib/igt_edid.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/lib/igt_edid.c b/lib/igt_edid.c
index 1c85486d..c31a4a4f 100644
--- a/lib/igt_edid.c
+++ b/lib/igt_edid.c
@@ -350,25 +350,21 @@ void cea_sad_init_pcm(struct cea_sad *sad, int channels,
  */
 const struct cea_vsdb *cea_vsdb_get_hdmi_default(size_t *size)
 {
-	/* We'll generate a VSDB with 2 extension fields. */
-	static char raw[CEA_VSDB_HDMI_MIN_SIZE + 2] = {0};
-	struct cea_vsdb *vsdb;
-	struct hdmi_vsdb *hdmi;
+	static struct cea_vsdb vsdb = {0};
 
-	*size = sizeof(raw);
+	/* We'll generate a VSDB with 2 extension fields. */
+	*size = CEA_VSDB_HDMI_MIN_SIZE + 2;
 
 	/* Magic incantation. Works better if you orient your screen in the
 	 * direction of the VESA headquarters. */
-	vsdb = (struct cea_vsdb *) raw;
-	memcpy(vsdb->ieee_oui, hdmi_ieee_oui, sizeof(hdmi_ieee_oui));
-	hdmi = &vsdb->data.hdmi;
-	hdmi->src_phy_addr[0] = 0x10;
-	hdmi->src_phy_addr[1] = 0x00;
+	memcpy(vsdb.ieee_oui, hdmi_ieee_oui, sizeof(hdmi_ieee_oui));
+	vsdb.data.hdmi.src_phy_addr[0] = 0x10;
+	vsdb.data.hdmi.src_phy_addr[1] = 0x00;
 	/* 2 VSDB extension fields */
-	hdmi->flags1 = 0x38;
-	hdmi->max_tdms_clock = 0x2D;
+	vsdb.data.hdmi.flags1 = 0x38;
+	vsdb.data.hdmi.max_tdms_clock = 0x2D;
 
-	return vsdb;
+	return &vsdb;
 }
 
 static void edid_cea_data_block_init(struct edid_cea_data_block *block,
-- 
2.30.1



More information about the igt-dev mailing list