]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
util: mkimage, fix gcc5 build failure
authorJiri Slaby <jslaby@suse.cz>
Thu, 12 Feb 2015 10:02:09 +0000 (11:02 +0100)
committerAndrei Borzenkov <arvidjaar@gmail.com>
Thu, 12 Feb 2015 19:18:01 +0000 (22:18 +0300)
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

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
util/mkimage.c

index bccd70388afa3122d6879278629321b22cf69f86..7821dc5eaf11b8ba59edf45e3a8b6136ae530edc 100644 (file)
@@ -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;