Skip to contentSkip to conversation

Fix some type comparison problems

PATCH In review Xiao Ni 3 participants 3 messages Feb 3, 2016 – Feb 4, 2016 MD RAID

lore
Share & tools
lore

Xiao Ni

author
#0 lore raw

PATCH 1/1 Fix some type comparison problems

It complains when building on s390 and i686 platform.

---
 Monitor.c | 2 +-
 util.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Monitor.c +1 -1
index f19c2e5..928aa45 100644
@@ -542,7 +542,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
 		alert("NewArray", st->devname, NULL, ainfo);
 	}
 
-	if (st->utime == array.utime &&
+	if (st->utime == (long)array.utime &&
 	    st->failed == array.failed_disks &&
 	    st->working == array.working_disks &&
 	    st->spare == array.spare_disks &&
util.c +1 -1
index 970d484..ccbb2bc 100644
@@ -1288,7 +1288,7 @@ struct supertype *guess_super_type(int fd, enum guess_types guess_type)
 			struct mdinfo info;
 			st->ss->getinfo_super(st, &info, NULL);
 			if (bestsuper == -1 ||
-			    besttime < info.array.ctime) {
+			    besttime < (time_t)info.array.ctime) {
 				bestsuper = i;
 				besttime = info.array.ctime;
 			}
Signature · 1 line
2.4.3
#1 lore raw
Quoted 13 lines · Xiao Ni

It complains when building on s390 and i686 platform.

---
 Monitor.c | 2 +-
 util.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Monitor.c +0 -0
index f19c2e5..928aa45 100644

Monitor.c static int check_array(struct state *st, struct mdstat_ent *mdstat, · line 548

Quoted 8 lines
Monitor.c +1 -1
@@ -542,7 +542,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
 		alert("NewArray", st->devname, NULL, ainfo);
 	}
 
-	if (st->utime == array.utime &&
+	if (st->utime == (long)array.utime &&
 	    st->failed == array.failed_disks &&
 	    st->working == array.working_disks &&
 	    st->spare == array.spare_disks &&

Hi Xiao,

Thanks for the patch - I think the correct fix in Monitor.c is to change utime in struct state from long to unsigned int, to match the change Deepa Dinamani introduced in 26714713cd2bad9e0bf7f4669f6cc4659ceaab6c utime is only ever derived from mdu_array_info_s, so it should be safe.

util.c struct supertype *guess_super_type(int fd, enum guess_types guess_type) · line 1294

Quoted 13 lines
util.c +1 -1
index 970d484..ccbb2bc 100644
@@ -1288,7 +1288,7 @@ struct supertype *guess_super_type(int fd, enum guess_types guess_type)
 			struct mdinfo info;
 			st->ss->getinfo_super(st, &info, NULL);
 			if (bestsuper == -1 ||
-			    besttime < info.array.ctime) {
+			    besttime < (time_t)info.array.ctime) {
 				bestsuper = i;
 				besttime = info.array.ctime;
 			}

Here I think we should change the declaration of besttime from time_t to unsigned int, again to match the definition used in mdu_array_info_s.

That or we should change mdu_array_info_s to use time_t instead, but I am not sure that would be safe.

Cheers,
Jes

#2 lore raw
Quoted 47 lines · Jes Sorensen
Quoted 13 lines · Xiao Ni

It complains when building on s390 and i686 platform.

---
 Monitor.c | 2 +-
 util.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Monitor.c +0 -0
index f19c2e5..928aa45 100644

Monitor.c static int check_array(struct state *st, struct mdstat_ent *mdstat, · line 548

Quoted 8 lines
Monitor.c +1 -1
@@ -542,7 +542,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
              alert("NewArray", st->devname, NULL, ainfo);
      }
 
-     if (st->utime == array.utime &&
+     if (st->utime == (long)array.utime &&
          st->failed == array.failed_disks &&
          st->working == array.working_disks &&
          st->spare == array.spare_disks &&

Hi Xiao,

Thanks for the patch - I think the correct fix in Monitor.c is to change utime in struct state from long to unsigned int, to match the change Deepa Dinamani introduced in 26714713cd2bad9e0bf7f4669f6cc4659ceaab6c utime is only ever derived from mdu_array_info_s, so it should be safe.

util.c struct supertype *guess_super_type(int fd, enum guess_types guess_type) · line 1294

Quoted 13 lines
util.c +1 -1
index 970d484..ccbb2bc 100644
@@ -1288,7 +1288,7 @@ struct supertype *guess_super_type(int fd, enum guess_types guess_type)
                      struct mdinfo info;
                      st->ss->getinfo_super(st, &info, NULL);
                      if (bestsuper == -1 ||
-                         besttime < info.array.ctime) {
+                         besttime < (time_t)info.array.ctime) {
                              bestsuper = i;
                              besttime = info.array.ctime;
                      }

Here I think we should change the declaration of besttime from time_t to unsigned int, again to match the definition used in mdu_array_info_s.

Quoted 2 lines

That or we should change mdu_array_info_s to use time_t instead, but I am not sure that would be safe.

It should be changed to unsigned int.
time_t is not long enough to hold timestamps after the year 2038(INT_MAX) as long is 32 bits on 32 bit systems.
It was changed to unsigned int to extend it until the year 2106.

-Deepa