From: Nadav Har'El <[email protected]>
Committer: Nadav Har'El <[email protected]>
Branch: master
Avoid unsized array in union
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]>
Message-Id: <[email protected]>
---
diff --git a/tools/cpiod/cpio.cc b/tools/cpiod/cpio.cc
--- a/tools/cpiod/cpio.cc
+++ b/tools/cpiod/cpio.cc
@@ -66,25 +66,21 @@ 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);
string name{namebuf.get(), namesize - 1};
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;
--
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.