Skip to contentSkip to conversation

vt: Replace 0-length array with flexible array

PATCH In review Kees Cook 2 participants 2 messages Jan 5, 2023 – Jan 9, 2023 TTY layer and serial drivers

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 vt: Replace 0-length array with flexible array

Zero-length arrays are deprecated[1]. Replace struct uni_screen's "lines" 0-length array with a flexible array. Detected with GCC 13, using -fstrict-flex-arrays=3:

../drivers/tty/vt/vt.c: In function 'vc_uniscr_copy_area':
../drivers/tty/vt/vt.c:488:48: warning: array subscript dst_row is outside array bounds of 'char32_t *[0]' {aka 'unsigned int *[]'} [-Warray-bounds=]

  488 |                 char32_t *dst_line = dst->lines[dst_row];
      |                                      ~~~~~~~~~~^~~~~~~~~

../drivers/tty/vt/vt.c:335:19: note: while referencing 'lines'
335 | char32_t *lines[0];
| ^~~~~

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc "Ilpo Järvinen" <[email protected]>
Cc Helge Deller <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
---
 drivers/tty/vt/vt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/vt/vt.c +1 -1
index 981d2bfcf9a5..b1445f00f616 100644
@@ -332,7 +332,7 @@ typedef uint32_t char32_t;
  * scrolling only implies some pointer shuffling.
  */
 struct uni_screen {
-	char32_t *lines[0];
+	DECLARE_FLEX_ARRAY(char32_t *, lines);
 };
 
 static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 30 lines · Kees Cook

Zero-length arrays are deprecated[1]. Replace struct uni_screen's "lines" 0-length array with a flexible array. Detected with GCC 13, using -fstrict-flex-arrays=3:

../drivers/tty/vt/vt.c: In function 'vc_uniscr_copy_area':
../drivers/tty/vt/vt.c:488:48: warning: array subscript dst_row is outside array bounds of 'char32_t *[0]' {aka 'unsigned int *[]'} [-Warray-bounds=]

   488 |                 char32_t *dst_line = dst->lines[dst_row];
       |                                      ~~~~~~~~~~^~~~~~~~~

../drivers/tty/vt/vt.c:335:19: note: while referencing 'lines'
335 | char32_t *lines[0];
| ^~~~~

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc "Ilpo Järvinen" <[email protected]>
Cc Helge Deller <[email protected]>
Cc "Gustavo A. R. Silva" <[email protected]>
---
  drivers/tty/vt/vt.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/vt/vt.c +0 -0
index 981d2bfcf9a5..b1445f00f616 100644

drivers/tty/vt/vt.c typedef uint32_t char32_t; · line 336

Quoted 6 lines
drivers/tty/vt/vt.c +1 -1
@@ -332,7 +332,7 @@ typedef uint32_t char32_t;
   * scrolling only implies some pointer shuffling.
   */
  struct uni_screen {
-	char32_t *lines[0];
+	DECLARE_FLEX_ARRAY(char32_t *, lines);
  };

Perhaps I am missing something, but why don't we simply have:
char32_t **uni_screen_lines;
? And even if we don't, we should likely convert to array_size() on the alloc site.

And a side note: what's actually the purpose of all that NO_VC_UNI_SCREEN and closely connected get_vc_uniscr()?

thanks,

Signature · 2 lines
js
suse labs