diff mbox

[ovs-dev] tun-metadata: Avoid MSVC compile error on 64-bit builds for 0-length array.

Message ID 1443501005-18192-1-git-send-email-blp@nicira.com
State Accepted
Headers show

Commit Message

Ben Pfaff Sept. 29, 2015, 4:30 a.m. UTC
MSVC does not support zero-size array unless it is the last member of
a defined structure.

The error is hit only on MSVC 64 bit because the size of
uint64_t is equal with sizeof(struct tun_table *).

Reported-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
---
 lib/tun-metadata.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Jesse Gross Sept. 29, 2015, 4:37 a.m. UTC | #1
On Mon, Sep 28, 2015 at 9:30 PM, Ben Pfaff <blp@nicira.com> wrote:
> MSVC does not support zero-size array unless it is the last member of
> a defined structure.
>
> The error is hit only on MSVC 64 bit because the size of
> uint64_t is equal with sizeof(struct tun_table *).
>
> Reported-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
> Signed-off-by: Ben Pfaff <blp@nicira.com>

Acked-by: Jesse Gross <jesse@nicira.com>
Ben Pfaff Sept. 29, 2015, 4:40 a.m. UTC | #2
On Mon, Sep 28, 2015 at 09:37:40PM -0700, Jesse Gross wrote:
> On Mon, Sep 28, 2015 at 9:30 PM, Ben Pfaff <blp@nicira.com> wrote:
> > MSVC does not support zero-size array unless it is the last member of
> > a defined structure.
> >
> > The error is hit only on MSVC 64 bit because the size of
> > uint64_t is equal with sizeof(struct tun_table *).
> >
> > Reported-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
> > Signed-off-by: Ben Pfaff <blp@nicira.com>
> 
> Acked-by: Jesse Gross <jesse@nicira.com>

Thanks Jesse, I applied this to master.
diff mbox

Patch

diff --git a/lib/tun-metadata.h b/lib/tun-metadata.h
index 624c881..71842b7 100644
--- a/lib/tun-metadata.h
+++ b/lib/tun-metadata.h
@@ -63,12 +63,17 @@  struct tun_metadata {
         uint8_t len;                       /* Length of data in 'opts'. */
     } present;
     struct tun_table *tab;      /* Types & lengths for 'opts' and 'opt_map'. */
-    uint8_t pad[sizeof(uint64_t) - sizeof(struct tun_table *)]; /* Make 8 bytes */
+
+#if UINTPTR_MAX == UINT32_MAX
+    uint8_t pad[4];             /* Pad to 64-bit boundary. */
+#endif
+
     union {
         uint8_t u8[TUN_METADATA_TOT_OPT_SIZE]; /* Values from tunnel TLVs. */
         struct geneve_opt gnv[GENEVE_TOT_OPT_SIZE / sizeof(struct geneve_opt)];
     } opts;
 };
+BUILD_ASSERT_DECL(offsetof(struct tun_metadata, opts) % 8 == 0);
 BUILD_ASSERT_DECL(sizeof(((struct tun_metadata *)0)->present.map) * 8 >=
                   TUN_METADATA_NUM_OPTS);