gfs2-utils: RHEL7 - fsck.gfs2: Fix 'initializer element is not constant' build error

Andrew Price andyp at fedoraproject.org
Tue Apr 7 21:23:50 UTC 2015


Gitweb:        http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=1be8d75fd107390cb422dabf25062f9f7423c25c
Commit:        1be8d75fd107390cb422dabf25062f9f7423c25c
Parent:        18894bea111515a8c2f8776df21b7c4396d63ae1
Author:        Andrew Price <anprice at redhat.com>
AuthorDate:    Tue Jan 27 11:39:35 2015 +0000
Committer:     Andrew Price <anprice at redhat.com>
CommitterDate: Wed Apr 1 16:51:35 2015 +0100

fsck.gfs2: Fix 'initializer element is not constant' build error

This error occurs when gfs2-utils is compiled with -std options more
recent than gnu89:

    CC       fsck_gfs2-main.o
  main.c:39:38: error: initializer element is not constant
   struct osi_root dup_blocks = (struct osi_root) { NULL, };
                                        ^
  main.c:40:35: error: initializer element is not constant
   struct osi_root dirtree = (struct osi_root) { NULL, };
                                     ^
  main.c:41:37: error: initializer element is not constant
   struct osi_root inodetree = (struct osi_root) { NULL, };
                                     ^
As far as I can tell, with C89/gnu89 the use of a cast in this context
is undefined behaviour and the later standards are more strict about it,
hence the error. As the standards specify that members of objects with
static storage duration are zeroed/NULLed anyway, the initializers can
be removed to achieve the intended result.

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 gfs2/fsck/main.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gfs2/fsck/main.c b/gfs2/fsck/main.c
index a4af25d..658cd17 100644
--- a/gfs2/fsck/main.c
+++ b/gfs2/fsck/main.c
@@ -36,9 +36,9 @@ const char *pass = "";
 uint64_t last_data_block;
 uint64_t first_data_block;
 int preen = 0, force_check = 0;
-struct osi_root dup_blocks = (struct osi_root) { NULL, };
-struct osi_root dirtree = (struct osi_root) { NULL, };
-struct osi_root inodetree = (struct osi_root) { NULL, };
+struct osi_root dup_blocks;
+struct osi_root dirtree;
+struct osi_root inodetree;
 int dups_found = 0, dups_found_first = 0;
 struct gfs_sb *sbd1 = NULL;
 int sb_fixed = 0;


More information about the cluster-commits mailing list