All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] kdd: remove zero-length arrays
@ 2020-06-08 20:38 Olaf Hering
  2020-06-09  8:55 ` Paul Durrant
  0 siblings, 1 reply; 18+ messages in thread
From: Olaf Hering @ 2020-06-08 20:38 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson, Olaf Hering, Tim Deegan, Wei Liu

Struct 'kdd_hdr' already has a member named 'payload[]' to easily
refer to the data after the header.  Remove the payload member from
'kdd_pkt' and always use 'kdd_hdr' to fix the following compile error:

kdd.c: In function 'kdd_tx':
kdd.c:746:30: error: array subscript 65534 is outside the bounds of an interior zero-length array 'uint8_t[0]' {aka 'unsigned char[]'} [-Werror=zero-length-bounds]
  746 |         sum += s->txp.payload[i];
      |                ~~~~~~~~~~~~~~^~~
In file included from kdd.c:53:
kdd.h:326:17: note: while referencing 'payload'
  326 |         uint8_t payload[0];
      |                 ^~~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 tools/debugger/kdd/kdd.c | 10 +++++-----
 tools/debugger/kdd/kdd.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/tools/debugger/kdd/kdd.c b/tools/debugger/kdd/kdd.c
index 3ebda9b12c..4c6b39c22b 100644
--- a/tools/debugger/kdd/kdd.c
+++ b/tools/debugger/kdd/kdd.c
@@ -249,7 +249,7 @@ static void kdd_log_pkt(kdd_state *s, char *name, kdd_pkt *p)
 
     /* Re-check the checksum */
     for (i = 0; i < p->h.len; i++)
-        sum += p->payload[i];
+        sum += p->h.payload[i];
 
     fprintf(f, "\n"
             "%s: %s type 0x%4.4"PRIx16" len 0x%4.4"PRIx16
@@ -267,8 +267,8 @@ static void kdd_log_pkt(kdd_state *s, char *name, kdd_pkt *p)
             fprintf(f, "%8.8x ", i);
         } else if (i % 8 == 0)
             fprintf(f, " ");
-        fprintf(f, " %2.2x", p->payload[i]);
-        ascii[i % 16] = (isprint(((int)p->payload[i])) ? p->payload[i] : 0x2e);
+        fprintf(f, " %2.2x", p->h.payload[i]);
+        ascii[i % 16] = (isprint(((int)p->h.payload[i])) ? p->h.payload[i] : 0x2e);
         if (i % 16 == 15)
             fprintf(f, "  |%s|\n", ascii);
     }
@@ -743,7 +743,7 @@ static void kdd_tx(kdd_state *s)
 
     /* Fix up the checksum before we send */
     for (i = 0; i < s->txp.h.len; i++)
-        sum += s->txp.payload[i];
+        sum += s->txp.h.payload[i];
     s->txp.h.sum = sum;
 
     kdd_log_pkt(s, "TX", &s->txp);
@@ -1127,7 +1127,7 @@ static void kdd_handle_pkt(kdd_state *s, kdd_pkt *p)
 
     /* Simple checksum: add all the bytes */
     for (i = 0; i < p->h.len; i++)
-        sum += p->payload[i];
+        sum += p->h.payload[i];
     if (p->h.sum != sum) {
         kdd_send_ack(s, p->h.id, KDD_ACK_BAD);
         return;
diff --git a/tools/debugger/kdd/kdd.h b/tools/debugger/kdd/kdd.h
index bfb00ba5c5..57525d36c6 100644
--- a/tools/debugger/kdd/kdd.h
+++ b/tools/debugger/kdd/kdd.h
@@ -68,7 +68,7 @@ typedef struct {
     uint16_t len;     /* Payload length, excl. header and trailing byte */
     uint32_t id;      /* Echoed in responses */
     uint32_t sum;     /* Unsigned sum of all payload bytes */
-    uint8_t payload[0];
+    uint8_t payload[];
 } PACKED kdd_hdr;
 
 #define KDD_PKT_CMD 0x0002      /* Debugger commands (and replies to them) */
@@ -323,7 +323,6 @@ typedef struct {
         kdd_msg msg;
         kdd_reg reg;
         kdd_stc stc;
-        uint8_t payload[0];
     };
 } PACKED kdd_pkt;
 


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2020-06-26 10:33 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-08 20:38 [PATCH v1] kdd: remove zero-length arrays Olaf Hering
2020-06-09  8:55 ` Paul Durrant
2020-06-09  9:00   ` Olaf Hering
2020-06-09  9:04     ` Paul Durrant
2020-06-09  9:06       ` Jürgen Groß
2020-06-09  9:08         ` Paul Durrant
2020-06-09  9:37       ` Olaf Hering
2020-06-09 12:15   ` Tim Deegan
2020-06-09 13:22     ` Olaf Hering
2020-06-09 13:26       ` Ian Jackson
2020-06-09 13:32         ` Olaf Hering
2020-06-10 19:16       ` Tim Deegan
2020-06-11 19:10         ` Olaf Hering
2020-06-16 20:50           ` Christopher Clark
2020-06-17  8:21             ` Paul Durrant
2020-06-26 10:26               ` Wei Liu
2020-06-26 10:31                 ` Paul Durrant
2020-06-26 10:33                   ` Wei Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.