gicmo / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone
e153146
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
e153146
From: Peter Jones <pjones@redhat.com>
e153146
Date: Thu, 11 Jul 2019 18:03:25 +0200
e153146
Subject: [PATCH] Attempt to fix up all the places -Wsign-compare=error finds.
e153146
e153146
Signed-off-by: Peter Jones <pjones@redhat.com>
e153146
---
e153146
 grub-core/kern/emu/misc.c                          |   2 +-
e153146
 grub-core/lib/reed_solomon.c                       |   4 +-
e153146
 grub-core/osdep/linux/blocklist.c                  |   2 +-
e153146
 grub-core/osdep/linux/getroot.c                    |   2 +-
e153146
 grub-core/osdep/linux/hostdisk.c                   |   2 +-
e153146
 util/grub-fstest.c                                 |   2 +-
e153146
 util/grub-menulst2cfg.c                            |   2 +-
e153146
 util/grub-mkfont.c                                 |  13 +-
e153146
 util/grub-probe.c                                  |   2 +-
e153146
 util/grub-rpm-sort.c                               |   2 +-
e153146
 util/setup.c                                       |   2 +-
e153146
 bootstrap.conf                                     |   2 +-
e153146
 .../gnulib-patches/fix-sign-compare-errors.patch   | 161 +++++++++++++++++++++
e153146
 13 files changed, 180 insertions(+), 18 deletions(-)
e153146
 create mode 100644 grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch
e153146
e153146
diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c
e153146
index 245b69cab51..7a8d9e62300 100644
e153146
--- a/grub-core/kern/emu/misc.c
e153146
+++ b/grub-core/kern/emu/misc.c
e153146
@@ -177,7 +177,7 @@ grub_util_get_image_size (const char *path)
e153146
   sz = ftello (f);
e153146
   if (sz < 0)
e153146
     grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
e153146
-  if (sz != (size_t) sz)
e153146
+  if (sz > (off_t)(GRUB_SIZE_MAX >> 1))
e153146
     grub_util_error (_("file `%s' is too big"), path);
e153146
   ret = (size_t) sz;
e153146
 
e153146
diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c
e153146
index ee9fa7b4feb..19c20085279 100644
e153146
--- a/grub-core/lib/reed_solomon.c
e153146
+++ b/grub-core/lib/reed_solomon.c
e153146
@@ -156,7 +156,7 @@ static void
e153146
 rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs)
e153146
 {
e153146
   gf_single_t *rs_polynomial;
e153146
-  int i, j;
e153146
+  unsigned int i, j;
e153146
   gf_single_t *m;
e153146
   m = xmalloc ((s + rs) * sizeof (gf_single_t));
e153146
   grub_memcpy (m, data, s * sizeof (gf_single_t));
e153146
@@ -325,7 +325,7 @@ static void
e153146
 encode_block (gf_single_t *ptr, grub_size_t s,
e153146
 	      gf_single_t *rptr, grub_size_t rs)
e153146
 {
e153146
-  int i, j;
e153146
+  unsigned int i, j;
e153146
   for (i = 0; i < SECTOR_SIZE; i++)
e153146
     {
e153146
       grub_size_t ds = (s + SECTOR_SIZE - 1 - i) / SECTOR_SIZE;
e153146
diff --git a/grub-core/osdep/linux/blocklist.c b/grub-core/osdep/linux/blocklist.c
e153146
index c77d6085ccb..42a315031ff 100644
e153146
--- a/grub-core/osdep/linux/blocklist.c
e153146
+++ b/grub-core/osdep/linux/blocklist.c
e153146
@@ -109,7 +109,7 @@ grub_install_get_blocklist (grub_device_t root_dev,
e153146
   else
e153146
     {
e153146
       struct fiemap *fie2;
e153146
-      int i;
e153146
+      unsigned int i;
e153146
       fie2 = xmalloc (sizeof (*fie2)
e153146
 		      + fie1.fm_mapped_extents
e153146
 		      * sizeof (fie1.fm_extents[1]));
e153146
diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c
e153146
index 4c5a13022dc..2b7a626d5ea 100644
e153146
--- a/grub-core/osdep/linux/getroot.c
e153146
+++ b/grub-core/osdep/linux/getroot.c
e153146
@@ -236,7 +236,7 @@ grub_find_root_devices_from_btrfs (const char *dir)
e153146
 {
e153146
   int fd;
e153146
   struct btrfs_ioctl_fs_info_args fsi;
e153146
-  int i, j = 0;
e153146
+  unsigned int i, j = 0;
e153146
   char **ret;
e153146
 
e153146
   fd = open (dir, 0);
e153146
diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c
e153146
index 8b92f8528f9..370d02787cd 100644
e153146
--- a/grub-core/osdep/linux/hostdisk.c
e153146
+++ b/grub-core/osdep/linux/hostdisk.c
e153146
@@ -83,7 +83,7 @@ grub_util_get_fd_size_os (grub_util_fd_t fd, const char *name, unsigned *log_sec
e153146
   if (sector_size & (sector_size - 1) || !sector_size)
e153146
     return -1;
e153146
   for (log_sector_size = 0;
e153146
-       (1 << log_sector_size) < sector_size;
e153146
+       (1U << log_sector_size) < sector_size;
e153146
        log_sector_size++);
e153146
 
e153146
   if (log_secsize)
e153146
diff --git a/util/grub-fstest.c b/util/grub-fstest.c
e153146
index f14e02d9727..88f9c5d4ad8 100644
e153146
--- a/util/grub-fstest.c
e153146
+++ b/util/grub-fstest.c
e153146
@@ -323,7 +323,7 @@ cmd_cmp (char *src, char *dest)
e153146
   read_file (src, cmp_hook, ff);
e153146
 
e153146
   {
e153146
-    grub_uint64_t pre;
e153146
+    long long pre;
e153146
     pre = ftell (ff);
e153146
     fseek (ff, 0, SEEK_END);
e153146
     if (pre != ftell (ff))
e153146
diff --git a/util/grub-menulst2cfg.c b/util/grub-menulst2cfg.c
e153146
index a39f8693947..358d604210b 100644
e153146
--- a/util/grub-menulst2cfg.c
e153146
+++ b/util/grub-menulst2cfg.c
e153146
@@ -34,7 +34,7 @@ main (int argc, char **argv)
e153146
   char *buf = NULL;
e153146
   size_t bufsize = 0;
e153146
   char *suffix = xstrdup ("");
e153146
-  int suffixlen = 0;
e153146
+  size_t suffixlen = 0;
e153146
   const char *out_fname = 0;
e153146
 
e153146
   grub_util_host_init (&argc, &argv);
e153146
diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c
e153146
index 0fe45a6103d..3e09240b99f 100644
e153146
--- a/util/grub-mkfont.c
e153146
+++ b/util/grub-mkfont.c
e153146
@@ -138,7 +138,8 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face,
e153146
   int width, height;
e153146
   int cuttop, cutbottom, cutleft, cutright;
e153146
   grub_uint8_t *data;
e153146
-  int mask, i, j, bitmap_size;
e153146
+  int mask, i, bitmap_size;
e153146
+  unsigned int j;
e153146
   FT_GlyphSlot glyph;
e153146
   int flag = FT_LOAD_RENDER | FT_LOAD_MONOCHROME;
e153146
   FT_Error err;
e153146
@@ -183,7 +184,7 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face,
e153146
     cuttop = cutbottom = cutleft = cutright = 0;
e153146
   else
e153146
     {
e153146
-      for (cuttop = 0; cuttop < glyph->bitmap.rows; cuttop++)
e153146
+      for (cuttop = 0; cuttop < (long)glyph->bitmap.rows; cuttop++)
e153146
 	{
e153146
 	  for (j = 0; j < glyph->bitmap.width; j++)
e153146
 	    if (glyph->bitmap.buffer[j / 8 + cuttop * glyph->bitmap.pitch]
e153146
@@ -203,10 +204,10 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face,
e153146
 	    break;
e153146
 	}
e153146
       cutbottom = glyph->bitmap.rows - 1 - cutbottom;
e153146
-      if (cutbottom + cuttop >= glyph->bitmap.rows)
e153146
+      if (cutbottom + cuttop >= (long)glyph->bitmap.rows)
e153146
 	cutbottom = 0;
e153146
 
e153146
-      for (cutleft = 0; cutleft < glyph->bitmap.width; cutleft++)
e153146
+      for (cutleft = 0; cutleft < (long)glyph->bitmap.width; cutleft++)
e153146
 	{
e153146
 	  for (j = 0; j < glyph->bitmap.rows; j++)
e153146
 	    if (glyph->bitmap.buffer[cutleft / 8 + j * glyph->bitmap.pitch]
e153146
@@ -225,7 +226,7 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face,
e153146
 	    break;
e153146
 	}
e153146
       cutright = glyph->bitmap.width - 1 - cutright;
e153146
-      if (cutright + cutleft >= glyph->bitmap.width)
e153146
+      if (cutright + cutleft >= (long)glyph->bitmap.width)
e153146
 	cutright = 0;
e153146
     }
e153146
 
e153146
@@ -262,7 +263,7 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face,
e153146
 
e153146
   mask = 0;
e153146
   data = &glyph_info->bitmap[0] - 1;
e153146
-  for (j = cuttop; j < height + cuttop; j++)
e153146
+  for (j = cuttop; j < (long)height + cuttop; j++)
e153146
     for (i = cutleft; i < width + cutleft; i++)
e153146
       add_pixel (&data, &mask,
e153146
 		 glyph->bitmap.buffer[i / 8 + j * glyph->bitmap.pitch] &
e153146
diff --git a/util/grub-probe.c b/util/grub-probe.c
e153146
index 81d27eead59..7481e487211 100644
e153146
--- a/util/grub-probe.c
e153146
+++ b/util/grub-probe.c
e153146
@@ -798,7 +798,7 @@ argp_parser (int key, char *arg, struct argp_state *state)
e153146
 
e153146
     case 't':
e153146
       {
e153146
-	int i;
e153146
+	unsigned int i;
e153146
 
e153146
 	for (i = PRINT_FS; i < ARRAY_SIZE (targets); i++)
e153146
 	  if (strcmp (arg, targets[i]) == 0)
e153146
diff --git a/util/grub-rpm-sort.c b/util/grub-rpm-sort.c
e153146
index f33bd1ed568..8345944105f 100644
e153146
--- a/util/grub-rpm-sort.c
e153146
+++ b/util/grub-rpm-sort.c
e153146
@@ -232,7 +232,7 @@ main (int argc, char *argv[])
e153146
   struct arguments arguments;
e153146
   char **package_names = NULL;
e153146
   size_t n_package_names = 0;
e153146
-  int i;
e153146
+  unsigned int i;
e153146
 
e153146
   grub_util_host_init (&argc, &argv);
e153146
 
e153146
diff --git a/util/setup.c b/util/setup.c
e153146
index 6f88f3cc43f..864094de682 100644
e153146
--- a/util/setup.c
e153146
+++ b/util/setup.c
e153146
@@ -402,7 +402,7 @@ SETUP (const char *dir,
e153146
     int is_ldm;
e153146
     grub_err_t err;
e153146
     grub_disk_addr_t *sectors;
e153146
-    int i;
e153146
+    unsigned int i;
e153146
     grub_fs_t fs;
e153146
     unsigned int nsec, maxsec;
e153146
 
e153146
diff --git a/bootstrap.conf b/bootstrap.conf
e153146
index 988dda099ac..8804d5beb89 100644
e153146
--- a/bootstrap.conf
e153146
+++ b/bootstrap.conf
e153146
@@ -78,7 +78,7 @@ cp -a INSTALL INSTALL.grub
e153146
 
e153146
 bootstrap_post_import_hook () {
e153146
   set -e
e153146
-  for patchname in fix-null-deref fix-width no-abort; do
e153146
+  for patchname in fix-null-deref fix-width no-abort fix-sign-compare-errors; do
e153146
     patch -d grub-core/lib/gnulib -p2 \
e153146
       < "grub-core/lib/gnulib-patches/$patchname.patch"
e153146
   done
e153146
diff --git a/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch b/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch
e153146
new file mode 100644
e153146
index 00000000000..479029c0565
e153146
--- /dev/null
e153146
+++ b/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch
e153146
@@ -0,0 +1,161 @@
e153146
+diff --git a/lib/regcomp.c b/lib/regcomp.c
e153146
+index cc85f35ac58..361079d82d6 100644
e153146
+--- a/lib/regcomp.c
e153146
++++ b/lib/regcomp.c
e153146
+@@ -322,7 +322,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
e153146
+ 		*p++ = dfa->nodes[node].opr.c;
e153146
+ 	      memset (&state, '\0', sizeof (state));
e153146
+ 	      if (__mbrtowc (&wc, (const char *) buf, p - buf,
e153146
+-			     &state) == p - buf
e153146
++			     &state) == (size_t)(p - buf)
e153146
+ 		  && (__wcrtomb ((char *) buf, __towlower (wc), &state)
e153146
+ 		      != (size_t) -1))
e153146
+ 		re_set_fastmap (fastmap, false, buf[0]);
e153146
+@@ -3778,7 +3778,7 @@ fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax)
e153146
+       num = ((token->type != CHARACTER || c < '0' || '9' < c || num == -2)
e153146
+ 	     ? -2
e153146
+ 	     : num == -1
e153146
+-	     ? c - '0'
e153146
++	     ? (Idx)(c - '0')
e153146
+ 	     : MIN (RE_DUP_MAX + 1, num * 10 + c - '0'));
e153146
+     }
e153146
+   return num;
e153146
+diff --git a/lib/regex_internal.c b/lib/regex_internal.c
e153146
+index 9004ce809eb..193a1e3d332 100644
e153146
+--- a/lib/regex_internal.c
e153146
++++ b/lib/regex_internal.c
e153146
+@@ -233,7 +233,7 @@ build_wcs_buffer (re_string_t *pstr)
e153146
+       /* Apply the translation if we need.  */
e153146
+       if (__glibc_unlikely (pstr->trans != NULL))
e153146
+ 	{
e153146
+-	  int i, ch;
e153146
++	  unsigned int i, ch;
e153146
+ 
e153146
+ 	  for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i)
e153146
+ 	    {
e153146
+@@ -376,7 +376,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
e153146
+ 	prev_st = pstr->cur_state;
e153146
+ 	if (__glibc_unlikely (pstr->trans != NULL))
e153146
+ 	  {
e153146
+-	    int i, ch;
e153146
++	    unsigned int i, ch;
e153146
+ 
e153146
+ 	    for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i)
e153146
+ 	      {
e153146
+@@ -754,7 +754,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
e153146
+ 			  memset (&cur_state, 0, sizeof (cur_state));
e153146
+ 			  mbclen = __mbrtowc (&wc2, (const char *) pp, mlen,
e153146
+ 					      &cur_state);
e153146
+-			  if (raw + offset - p <= mbclen
e153146
++			  if ((size_t)(raw + offset - p) <= mbclen
e153146
+ 			      && mbclen < (size_t) -2)
e153146
+ 			    {
e153146
+ 			      memset (&pstr->cur_state, '\0',
e153146
+diff --git a/lib/regex_internal.h b/lib/regex_internal.h
e153146
+index 5462419b787..e0f8292395d 100644
e153146
+--- a/lib/regex_internal.h
e153146
++++ b/lib/regex_internal.h
e153146
+@@ -425,7 +425,7 @@ struct re_string_t
e153146
+   unsigned char offsets_needed;
e153146
+   unsigned char newline_anchor;
e153146
+   unsigned char word_ops_used;
e153146
+-  int mb_cur_max;
e153146
++  unsigned int mb_cur_max;
e153146
+ };
e153146
+ typedef struct re_string_t re_string_t;
e153146
+ 
e153146
+@@ -702,7 +702,7 @@ struct re_dfa_t
e153146
+   unsigned int is_utf8 : 1;
e153146
+   unsigned int map_notascii : 1;
e153146
+   unsigned int word_ops_used : 1;
e153146
+-  int mb_cur_max;
e153146
++  unsigned int mb_cur_max;
e153146
+   bitset_t word_char;
e153146
+   reg_syntax_t syntax;
e153146
+   Idx *subexp_map;
e153146
+diff --git a/lib/regexec.c b/lib/regexec.c
e153146
+index 0a7a27b772e..b57d4f9141d 100644
e153146
+--- a/lib/regexec.c
e153146
++++ b/lib/regexec.c
e153146
+@@ -443,7 +443,7 @@ re_search_stub (struct re_pattern_buffer *bufp, const char *string, Idx length,
e153146
+     {
e153146
+       if (ret_len)
e153146
+ 	{
e153146
+-	  assert (pmatch[0].rm_so == start);
e153146
++	  assert (pmatch[0].rm_so == (long)start);
e153146
+ 	  rval = pmatch[0].rm_eo - start;
e153146
+ 	}
e153146
+       else
e153146
+@@ -877,11 +877,11 @@ re_search_internal (const regex_t *preg, const char *string, Idx length,
e153146
+ 	    if (__glibc_unlikely (mctx.input.offsets_needed != 0))
e153146
+ 	      {
e153146
+ 		pmatch[reg_idx].rm_so =
e153146
+-		  (pmatch[reg_idx].rm_so == mctx.input.valid_len
e153146
++		  (pmatch[reg_idx].rm_so == (long)mctx.input.valid_len
e153146
+ 		   ? mctx.input.valid_raw_len
e153146
+ 		   : mctx.input.offsets[pmatch[reg_idx].rm_so]);
e153146
+ 		pmatch[reg_idx].rm_eo =
e153146
+-		  (pmatch[reg_idx].rm_eo == mctx.input.valid_len
e153146
++		  (pmatch[reg_idx].rm_eo == (long)mctx.input.valid_len
e153146
+ 		   ? mctx.input.valid_raw_len
e153146
+ 		   : mctx.input.offsets[pmatch[reg_idx].rm_eo]);
e153146
+ 	      }
e153146
+@@ -1418,11 +1418,11 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
e153146
+     }
e153146
+   memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch);
e153146
+ 
e153146
+-  for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;)
e153146
++  for (idx = pmatch[0].rm_so; idx <= (long)pmatch[0].rm_eo ;)
e153146
+     {
e153146
+       update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch);
e153146
+ 
e153146
+-      if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node)
e153146
++      if (idx == (long)pmatch[0].rm_eo && cur_node == mctx->last_node)
e153146
+ 	{
e153146
+ 	  Idx reg_idx;
e153146
+ 	  if (fs)
e153146
+@@ -1519,7 +1519,7 @@ update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
e153146
+       if (reg_num < nmatch)
e153146
+ 	{
e153146
+ 	  /* We are at the last node of this sub expression.  */
e153146
+-	  if (pmatch[reg_num].rm_so < cur_idx)
e153146
++	  if (pmatch[reg_num].rm_so < (long)cur_idx)
e153146
+ 	    {
e153146
+ 	      pmatch[reg_num].rm_eo = cur_idx;
e153146
+ 	      /* This is a non-empty match or we are not inside an optional
e153146
+@@ -2938,7 +2938,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
e153146
+       mctx->state_log[str_idx] = cur_state;
e153146
+     }
e153146
+ 
e153146
+-  for (null_cnt = 0; str_idx < last_str && null_cnt <= mctx->max_mb_elem_len;)
e153146
++  for (null_cnt = 0; str_idx < last_str && null_cnt <= (long)mctx->max_mb_elem_len;)
e153146
+     {
e153146
+       re_node_set_empty (&next_nodes);
e153146
+       if (mctx->state_log[str_idx + 1])
e153146
+@@ -3718,7 +3718,7 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
e153146
+ 			 const re_string_t *input, Idx str_idx)
e153146
+ {
e153146
+   const re_token_t *node = dfa->nodes + node_idx;
e153146
+-  int char_len, elem_len;
e153146
++  unsigned int char_len, elem_len;
e153146
+   Idx i;
e153146
+ 
e153146
+   if (__glibc_unlikely (node->type == OP_UTF8_PERIOD))
e153146
+@@ -4066,7 +4066,7 @@ extend_buffers (re_match_context_t *mctx, int min_len)
e153146
+   /* Double the lengths of the buffers, but allocate at least MIN_LEN.  */
e153146
+   ret = re_string_realloc_buffers (pstr,
e153146
+ 				   MAX (min_len,
e153146
+-					MIN (pstr->len, pstr->bufs_len * 2)));
e153146
++					MIN ((long)pstr->len, pstr->bufs_len * 2)));
e153146
+   if (__glibc_unlikely (ret != REG_NOERROR))
e153146
+     return ret;
e153146
+ 
e153146
+@@ -4236,7 +4236,7 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from,
e153146
+     = (from == to ? -1 : 0);
e153146
+ 
e153146
+   mctx->bkref_ents[mctx->nbkref_ents++].more = 0;
e153146
+-  if (mctx->max_mb_elem_len < to - from)
e153146
++  if (mctx->max_mb_elem_len < (long)(to - from))
e153146
+     mctx->max_mb_elem_len = to - from;
e153146
+   return REG_NOERROR;
e153146
+ }