nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0116-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch

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