diff mbox series

[4/5] btrfs-progs: move a union with variable sized type to the end

Message ID 34378b3e8906ca7e24f981caf7296087767510ac.1674797823.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: minor fixes for clang warnings | expand

Commit Message

Qu Wenruo Jan. 27, 2023, 5:41 a.m. UTC
[WARNING]
Clang 15.0.7 gives the following warning:

  image/main.c:95:2: warning: field '' with variable sized type 'union metadump_struct::(anonymous at image/main.c:95:2)' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
          union {
          ^

[CAUSE]
The union contains meta_cluster, which variable sized:

  struct meta_cluster {
  	struct meta_cluster_header header;
  	struct meta_cluster_item items[];
  } __attribute__ ((__packed__));

Thus clang gives above warning since it's a GNU extension.

[FIX]
Just move the union to the end of the structure.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 image/main.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/image/main.c b/image/main.c
index ecf464e5b0a2..d4a1fe349d31 100644
--- a/image/main.c
+++ b/image/main.c
@@ -92,11 +92,6 @@  struct metadump_struct {
 	struct btrfs_root *root;
 	FILE *out;
 
-	union {
-		struct meta_cluster cluster;
-		char meta_cluster_bytes[IMAGE_BLOCK_SIZE];
-	};
-
 	pthread_t threads[MAX_WORKER_THREADS];
 	size_t num_threads;
 	pthread_mutex_t mutex;
@@ -119,6 +114,11 @@  struct metadump_struct {
 	enum sanitize_mode sanitize_names;
 
 	int error;
+
+	union {
+		struct meta_cluster cluster;
+		char meta_cluster_bytes[IMAGE_BLOCK_SIZE];
+	};
 };
 
 struct mdrestore_struct {