Skip to contentSkip to conversation

util: mkimage, fix gcc5 build failure

PATCH In review Jiri Slaby 2 participants 2 messages Feb 12, 2015

lore
Share & tools
lore

Jiri Slaby

author
#0 lore raw

PATCH 1/1 util: mkimage, fix gcc5 build failure

gcc5 reports:
../util/mkimage.c: In function 'grub_install_get_image_target':
../util/mkimage.c:954:5: error: loop exit may only be reached after undefined behavior [-Werror=aggressive-loop-optimizations]

     && j < ARRAY_SIZE (image_targets[i].names); j++)
     ^
../util/mkimage.c:953:39: note: possible undefined statement is here
      for (j = 0; image_targets[i].names[j]
                                        ^

Well, let's move the index 'j' test before accesing the array to:
1) make the loop obvious
2) make gcc happy

---
 util/mkimage.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
util/mkimage.c +2 -2
index bccd70388afa..7821dc5eaf11 100644
@@ -937,8 +937,8 @@ grub_install_get_image_target (const char *arg)
 {
   unsigned i, j;
   for (i = 0; i < ARRAY_SIZE (image_targets); i++)
-    for (j = 0; image_targets[i].names[j]
-	   && j < ARRAY_SIZE (image_targets[i].names); j++)
+    for (j = 0; j < ARRAY_SIZE (image_targets[i].names) &&
+		    image_targets[i].names[j]; j++)
       if (strcmp (arg, image_targets[i].names[j]) == 0)
 	return &image_targets[i];
   return NULL;
Signature · 1 line
2.2.2
#1 lore raw

pushed

В Thu, 12 Feb 2015 11:02:09 +0100
Jiri Slaby <[email protected]> пишет:

Quoted 33 lines

gcc5 reports:
../util/mkimage.c: In function 'grub_install_get_image_target':
../util/mkimage.c:954:5: error: loop exit may only be reached after undefined behavior [-Werror=aggressive-loop-optimizations]

     && j < ARRAY_SIZE (image_targets[i].names); j++)
     ^
../util/mkimage.c:953:39: note: possible undefined statement is here
      for (j = 0; image_targets[i].names[j]
                                        ^

Well, let's move the index 'j' test before accesing the array to:
1) make the loop obvious
2) make gcc happy

---
 util/mkimage.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
util/mkimage.c +2 -2
index bccd70388afa..7821dc5eaf11 100644
@@ -937,8 +937,8 @@ grub_install_get_image_target (const char *arg)
 {
   unsigned i, j;
   for (i = 0; i < ARRAY_SIZE (image_targets); i++)
-    for (j = 0; image_targets[i].names[j]
-	   && j < ARRAY_SIZE (image_targets[i].names); j++)
+    for (j = 0; j < ARRAY_SIZE (image_targets[i].names) &&
+		    image_targets[i].names[j]; j++)
       if (strcmp (arg, image_targets[i].names[j]) == 0)
 	return &image_targets[i];
   return NULL;