Gcc 6 does not like an unsized array in a union. Fortunately, there
was no real reason for this trickery in the first place - a
traditional cast to char* works just as well.

Signed-off-by: Nadav Har'El <[email protected]>
---
 tools/cpiod/cpio.cc | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/tools/cpiod/cpio.cc b/tools/cpiod/cpio.cc
index 2d6e342..26b0ea3 100644
--- a/tools/cpiod/cpio.cc
+++ b/tools/cpiod/cpio.cc
@@ -66,16 +66,12 @@ cpio_in::~cpio_in()
 
 bool cpio_in::parse_one(istream& is, cpio_in& out)
 {
-    union {
-        cpio_newc_header header;
-        char data[];
-    } header;
-    is.read(header.data, sizeof(header));
-    auto& h = header.header;
-    if (strncmp(cpio_magic, h.c_magic, 6) != 0) {
-        throw runtime_error(string("bad cpio magic: '") + string(h.c_magic, 6) 
+ "'");
+    cpio_newc_header header;
+    is.read((char*)&header, sizeof(header));
+    if (strncmp(cpio_magic, header.c_magic, 6) != 0) {
+        throw runtime_error(string("bad cpio magic: '") + 
string(header.c_magic, 6) + "'");
     }
-    auto namesize = convert(h.c_namesize);
+    auto namesize = convert(header.c_namesize);
     auto aligned = align_up(sizeof(header) + namesize, sizeof(uint32_t)) - 
sizeof(header);
     unique_ptr<char[]> namebuf{new char[aligned]};
     is.read(namebuf.get(), aligned);
@@ -83,8 +79,8 @@ bool cpio_in::parse_one(istream& is, cpio_in& out)
     if (name == "TRAILER!!!") {
         return false;
     }
-    auto mode = convert(h.c_mode);
-    auto filesize = convert(h.c_filesize);
+    auto mode = convert(header.c_mode);
+    auto filesize = convert(header.c_filesize);
     auto aligned_filesize = align_up(filesize, 4u);
 
     auto type = mode & 0170000;
-- 
2.5.5

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to