>../../../grub-core/normal/charset.c: In function 'grub_bidi_line_logical_to_visual': ../../../grub-core/normal/charset.c:737: error: cannot optimize possibly infinite > loops If I do what is already done for GRUB_LONG_MIN and use: #define GRUB_INT_MIN (-0x7fffffff - 1) ...then gcc 4.6 is happy. gcc 4.4 goes on complaining
> about the inability to optimize possibly infinite loops.
in charset.c we actually want to ensure that it doesn't go negative. In grub-mkfont.c it's ok to disable warning altogether. Here is the patch (+grub-install fix)


--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko

=== modified file 'conf/Makefile.common'
--- conf/Makefile.common	2012-02-22 15:27:39 +0000
+++ conf/Makefile.common	2012-02-22 17:26:03 +0000
@@ -104,7 +104,7 @@
 CFLAGS_GCRY = -Wno-error -Wno-missing-field-initializers
 CPPFLAGS_GCRY = -I$(top_srcdir)/grub-core/lib/libgcrypt_wrap
 
-CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion -Wno-old-style-definition
+CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion -Wno-old-style-definition -Wno-unsafe-loop-optimizations
 CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/gnulib -I$(top_srcdir)/grub-core/gnulib
 
 CFLAGS_POSIX = -fno-builtin

=== modified file 'configure.ac'
--- configure.ac	2012-02-22 03:56:45 +0000
+++ configure.ac	2012-02-22 16:51:06 +0000
@@ -377,9 +377,9 @@
 LIBS=""
 
 # debug flags.
-WARN_FLAGS="-Wall -W -Wshadow -Wold-style-declaration -Wold-style-definition -Wpointer-arith -Wundef -Wextra -Waddress -Warray-bounds -Wattributes -Wbuiltin-macro-redefined -Wcast-align -Wchar-subscripts -Wclobbered -Wcomment -Wcoverage-mismatch -Wdeprecated -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wempty-body -Wendif-labels -Wfloat-equal -Wformat-contains-nul -Wformat-extra-args -Wformat-security -Wformat-y2k -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wunsafe-loop-optimizations -Wlogical-op -Wmain -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-noreturn -Wmudflap -Wmultichar -Wnonnull -Woverflow -Wpacked-bitfield-compat -Wparentheses -Wpointer-arith -Wpointer-to-int-cast -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wstrict-aliasing -Wswitch -Wsync-nand -Wtrigraphs  -Wtype-limits -Wundef -Wuninitialized -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value  -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wmissing-declarations -Wmissing-parameter-type  -Wmissing-prototypes -Wnested-externs -Wstrict-prototypes -Wpointer-sign"
+WARN_FLAGS="-Wall -W -Wshadow -Wold-style-declaration -Wold-style-definition -Wpointer-arith -Wundef -Wextra -Waddress -Warray-bounds -Wattributes -Wbuiltin-macro-redefined -Wcast-align -Wchar-subscripts -Wclobbered -Wcomment -Wcoverage-mismatch -Wdeprecated -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wempty-body -Wendif-labels -Wfloat-equal -Wformat-contains-nul -Wformat-extra-args -Wformat-security -Wformat-y2k -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wunsafe-loop-optimizations -Wlogical-op -Wmain -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-noreturn -Wmudflap -Wmultichar -Wnonnull -Woverflow -Wpacked-bitfield-compat -Wparentheses -Wpointer-arith -Wpointer-to-int-cast -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wstrict-aliasing -Wswitch -Wsync-nand -Wtrigraphs  -Wtype-limits -Wundef -Wuninitialized -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value  -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wmissing-parameter-type -Wnested-externs -Wstrict-prototypes -Wpointer-sign"
 HOST_CFLAGS="$HOST_CFLAGS $WARN_FLAGS"
-TARGET_CFLAGS="$TARGET_CFLAGS $WARN_FLAGS -g -Wredundant-decls -Wmissing-prototypes"
+TARGET_CFLAGS="$TARGET_CFLAGS $WARN_FLAGS -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations"
 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -g"
 
 # Force no alignment to save space on i386.

=== modified file 'grub-core/commands/legacycfg.c'
--- grub-core/commands/legacycfg.c	2012-02-12 14:25:25 +0000
+++ grub-core/commands/legacycfg.c	2012-02-22 18:58:57 +0000
@@ -543,15 +543,17 @@
   grub_uint8_t hash[MD5_HASHLEN];
 };
 
+#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
+
 static int
 check_password_md5_real (const char *entered,
 			 struct legacy_md5_password *pw)
 {
-  int enteredlen = grub_strlen (entered);
+  grub_size_t enteredlen = grub_strlen (entered);
   unsigned char alt_result[MD5_HASHLEN];
   unsigned char *digest;
   grub_uint8_t ctx[GRUB_MD_MD5->contextsize];
-  int i;
+  grub_size_t i;
 
   GRUB_MD_MD5->init (ctx);
   GRUB_MD_MD5->write (ctx, entered, enteredlen);

=== modified file 'grub-core/commands/testload.c'
--- grub-core/commands/testload.c	2012-02-22 04:04:54 +0000
+++ grub-core/commands/testload.c	2012-02-22 16:25:36 +0000
@@ -77,19 +77,24 @@
   grub_printf ("Reading %s sequentially again", argv[0]);
   grub_file_seek (file, 0);
 
-  for (pos = 0; pos < size; pos += GRUB_DISK_SECTOR_SIZE)
+  for (pos = 0; pos < size;)
     {
       char sector[GRUB_DISK_SECTOR_SIZE];
-
-      if (grub_file_read (file, sector, GRUB_DISK_SECTOR_SIZE)
-	  != GRUB_DISK_SECTOR_SIZE)
+      grub_size_t curlen = GRUB_DISK_SECTOR_SIZE;
+
+      if (curlen > size - pos)
+	curlen = size - pos;
+
+      if (grub_file_read (file, sector, curlen)
+	  != (grub_ssize_t) curlen)
 	goto fail;
 
-      if (grub_memcmp (sector, buf + pos, GRUB_DISK_SECTOR_SIZE) != 0)
+      if (grub_memcmp (sector, buf + pos, curlen) != 0)
 	{
 	  grub_printf ("\nDiffers in %lld\n", (unsigned long long) pos);
 	  goto fail;
 	}
+      pos += curlen;
     }
   grub_printf (" Done.\n");
 

=== modified file 'grub-core/disk/diskfilter.c'
--- grub-core/disk/diskfilter.c	2012-02-12 14:25:25 +0000
+++ grub-core/disk/diskfilter.c	2012-02-23 05:42:14 +0000
@@ -972,35 +972,40 @@
 	: (pv->id.id == id->id))
       {
 	struct grub_diskfilter_lv *lv;
+	grub_disk_t disk;
 	/* FIXME: Check whether the update time of the superblocks are
 	   the same.  */
+	disk = grub_disk_open (disk->name);
+	if (!disk)
+	  return grub_errno;
+	if (disk && pv->disk && grub_disk_get_size (disk) >= pv->part_size)
+	  {
+	    grub_disk_close (disk);
+	    return GRUB_ERR_NONE;
+	  }
+	pv->disk = disk;
 	/* This could happen to LVM on RAID, pv->disk points to the
 	   raid device, we shouldn't change it.  */
-	if (! pv->disk)
-	  {
-	    pv->disk = grub_disk_open (disk->name);
-	    if (! pv->disk)
-	      return grub_errno;
-	    pv->part_start = grub_partition_get_start (disk->partition);
-	    pv->part_size = grub_disk_get_size (disk);
+	pv->start_sector -= pv->part_start;
+	pv->part_start = grub_partition_get_start (disk->partition);
+	pv->part_size = grub_disk_get_size (disk);
 
 #ifdef GRUB_UTIL
-	    {
-	      grub_size_t s = 1;
-	      grub_partition_t p;
-	      for (p = disk->partition; p; p = p->parent)
-		s++;
-	      pv->partmaps = xmalloc (s * sizeof (pv->partmaps[0]));
-	      s = 0;
-	      for (p = disk->partition; p; p = p->parent)
-		pv->partmaps[s++] = xstrdup (p->partmap->name);
-	      pv->partmaps[s++] = 0;
-	    }
+	{
+	  grub_size_t s = 1;
+	  grub_partition_t p;
+	  for (p = disk->partition; p; p = p->parent)
+	    s++;
+	  pv->partmaps = xmalloc (s * sizeof (pv->partmaps[0]));
+	  s = 0;
+	  for (p = disk->partition; p; p = p->parent)
+	    pv->partmaps[s++] = xstrdup (p->partmap->name);
+	  pv->partmaps[s++] = 0;
+	}
 #endif
-	    if (start_sector != (grub_uint64_t)-1)
-	      pv->start_sector = start_sector;
-	    pv->start_sector += pv->part_start;
-	  }
+	if (start_sector != (grub_uint64_t)-1)
+	  pv->start_sector = start_sector;
+	pv->start_sector += pv->part_start;
 	/* Add the device to the array. */
 	for (lv = array->lvs; lv; lv = lv->next)
 	  if (!lv->became_readable_at && lv->fullname && is_lv_readable (lv))

=== modified file 'grub-core/disk/ldm.c'
--- grub-core/disk/ldm.c	2012-02-10 11:36:02 +0000
+++ grub-core/disk/ldm.c	2012-02-22 17:26:19 +0000
@@ -831,7 +831,7 @@
 {
   struct grub_diskfilter_pv *pv = NULL;
   struct grub_diskfilter_vg *vg = NULL;
-  struct grub_diskfilter_lv *res, *lv;
+  struct grub_diskfilter_lv *res = 0, *lv, *res_lv = 0;
 
   pv = grub_diskfilter_get_pv_from_disk (disk, &vg);
 
@@ -844,19 +844,21 @@
 	&& lv->segments->nodes->pv == pv
 	&& lv->segments->nodes->start + pv->start_sector == start)
       {
-	res = lv;
+	res_lv = lv;
 	break;
       }
+  if (!res_lv)
+    return NULL;
   for (lv = vg->lvs; lv; lv = lv->next)
     if (lv->segment_count == 1 && lv->segments->node_count == 1
 	&& lv->segments->type == GRUB_DISKFILTER_MIRROR
-	&& lv->segments->nodes->lv == lv)
+	&& lv->segments->nodes->lv == res_lv)
       {
 	res = lv;
 	break;
       }
-  if (res->fullname)
-    return grub_strdup (lv->fullname);
+  if (res && res->fullname)
+    return grub_strdup (res->fullname);
   return NULL;
 }
 

=== modified file 'grub-core/fs/zfs/zfs_sha256.c'
--- grub-core/fs/zfs/zfs_sha256.c	2010-12-01 21:55:26 +0000
+++ grub-core/fs/zfs/zfs_sha256.c	2012-02-22 16:17:39 +0000
@@ -129,7 +129,7 @@
   for (i = 0; i < 8; i++)
     pad[padsize++] = (size << 3) >> (56 - 8 * i);
   
-  for (i = 0; i < padsize; i += 64)
+  for (i = 0; i < padsize && i <= 64; i += 64)
     SHA256Transform(H, pad + i);
   
   zcp->zc_word[0] = grub_cpu_to_zfs64 ((grub_uint64_t)H[0] << 32 | H[1], 

=== modified file 'grub-core/io/gzio.c'
--- grub-core/io/gzio.c	2012-02-12 14:25:25 +0000
+++ grub-core/io/gzio.c	2012-02-22 16:45:45 +0000
@@ -363,6 +363,8 @@
   0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
 };
 
+#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
+
 #define NEEDBITS(n) do {while(k<(n)){b|=((ulg)get_byte(gzio))<<k;k+=8;}} while (0)
 #define DUMPBITS(n) do {b>>=(n);k-=(n);} while (0)
 

=== modified file 'grub-core/lib/LzmaEnc.c'
--- grub-core/lib/LzmaEnc.c	2012-02-10 15:48:48 +0000
+++ grub-core/lib/LzmaEnc.c	2012-02-22 16:16:26 +0000
@@ -1211,7 +1211,7 @@
       {
         UInt32 i;
         reps[0] = prevOpt->backs[pos];
-        for (i = 1; i <= pos; i++)
+        for (i = 1; i < pos + 1; i++)
           reps[i] = prevOpt->backs[i - 1];
         for (; i < LZMA_NUM_REPS; i++)
           reps[i] = prevOpt->backs[i];

=== modified file 'grub-core/net/net.c'
--- grub-core/net/net.c	2012-02-21 15:16:45 +0000
+++ grub-core/net/net.c	2012-02-22 18:55:00 +0000
@@ -608,8 +608,8 @@
 			struct grub_net_network_level_interface **interf)
 {
   struct grub_net_route *route;
-  int depth = 0;
-  int routecnt = 0;
+  unsigned int depth = 0;
+  unsigned int routecnt = 0;
   struct grub_net_network_level_protocol *prot = NULL;
   grub_net_network_level_address_t curtarget = addr;
 
@@ -618,7 +618,7 @@
   FOR_NET_ROUTES(route)
     routecnt++;
 
-  for (depth = 0; depth < routecnt + 2; depth++)
+  for (depth = 0; depth < routecnt + 2 && depth < GRUB_UINT_MAX; depth++)
     {
       struct grub_net_route *bestroute = NULL;
       FOR_NET_ROUTES(route)

=== modified file 'grub-core/normal/charset.c'
--- grub-core/normal/charset.c	2012-02-22 04:19:11 +0000
+++ grub-core/normal/charset.c	2012-02-23 05:46:26 +0000
@@ -734,7 +734,8 @@
 	  {
 	    int right_join = 0;
 	    signed i;
-	    for (i = k - 1; i > (signed) line_start - 1; i--)
+	    for (i = k - 1; i > (signed) line_start - 1 && i >= 0;
+		 i--)
 	      {
 		enum grub_join_type join_type = get_join_type (visual[i].base);
 		if (!(visual[i].attributes

=== modified file 'grub-core/normal/cmdline.c'
--- grub-core/normal/cmdline.c	2012-02-12 18:24:23 +0000
+++ grub-core/normal/cmdline.c	2012-02-22 16:21:47 +0000
@@ -49,13 +49,13 @@
       /* Remove the lines that don't fit in the new buffer.  */
       if (newsize < hist_used)
 	{
-	  int i;
-	  int delsize = hist_used - newsize;
+	  grub_size_t i;
+	  grub_size_t delsize = hist_used - newsize;
 	  hist_used = newsize;
 
-	  for (i = 1; i <= delsize; i++)
+	  for (i = 1; i < delsize + 1; i++)
 	    {
-	      int pos = hist_end - i;
+	      grub_ssize_t pos = hist_end - i;
 	      if (pos < 0)
 		pos += hist_size;
 	      grub_free (old_hist_lines[pos]);

=== modified file 'grub-core/script/parser.y'
--- grub-core/script/parser.y	2012-02-10 15:48:48 +0000
+++ grub-core/script/parser.y	2012-02-22 17:31:45 +0000
@@ -31,6 +31,9 @@
 #include "grub_script.tab.h"
 
 #pragma GCC diagnostic ignored "-Wunreachable-code"
+#pragma GCC diagnostic ignored "-Wmissing-declarations"
+#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
+
 %}
 
 %union {

=== modified file 'grub-core/script/yylex.l'
--- grub-core/script/yylex.l	2012-02-03 10:56:49 +0000
+++ grub-core/script/yylex.l	2012-02-22 16:49:25 +0000
@@ -27,6 +27,8 @@
 
 #pragma GCC diagnostic ignored "-Wunused-parameter"
 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
+#pragma GCC diagnostic ignored "-Wmissing-declarations"
+#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
 
 #define yyfree    grub_lexer_yyfree
 #define yyalloc   grub_lexer_yyalloc

=== modified file 'util/grub-install.in'
--- util/grub-install.in	2012-02-10 17:16:27 +0000
+++ util/grub-install.in	2012-02-23 05:58:48 +0000
@@ -633,8 +633,8 @@
 	    exit 1
 	fi
         # Get the Open Firmware device tree path translation.
-	dev="`echo $grub_device | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`"
-	partno="`echo $grub_device | sed -e 's/.*[^0-9]\([0-9]\+\)$/\1/'`"
+	dev="`echo $install_device | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`"
+	partno="`echo $install_device | sed -e 's/.*[^0-9]\([0-9]\+\)$/\1/'`"
 	ofpath="`$ofpathname $dev`" || {
 	    gettext_printf "Couldn't find IEEE1275 device tree path for %s.\nYou will have to set \`boot-device' variable manually.\n" "$dev" 1>&2
 	    exit 1

=== modified file 'util/grub-mkfont.c'
--- util/grub-mkfont.c	2012-02-10 12:31:43 +0000
+++ util/grub-mkfont.c	2012-02-23 06:15:32 +0000
@@ -681,6 +681,8 @@
   *offset += 10;
 }
 
+#pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
+
 static void
 print_glyphs (struct grub_font_info *font_info)
 {
@@ -717,7 +719,7 @@
 
       bitmap = glyph->bitmap;
       mask = 0x80;
-      for (y = ymax - 1; y >= ymin; y--)
+      for (y = ymax - 1; y > ymin - 1; y--)
 	{
 	  int line_pos;
 

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to