]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
video/fb/fbfill: Use unsigned integers for width/height
authorDaniel Axtens <dja@axtens.net>
Thu, 1 Apr 2021 15:22:04 +0000 (02:22 +1100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Mon, 12 Apr 2021 14:56:45 +0000 (16:56 +0200)
Since commit 7ce3259f67ac (video/fb/fbfill: Fix potential integer
overflow), clang builds of grub-emu have failed with messages like:

  /usr/bin/ld: libgrubmods.a(libgrubmods_a-fbfill.o): in function `grub_video_fbfill_direct24':
  fbfill.c:(.text+0x28e): undefined reference to `__muloti4'

This appears to be due to a weird quirk in how clang compiles

  grub_mul(dst->mode_info->bytes_per_pixel, width, &rowskip)

which is grub_mul(unsigned int, int, &grub_size_t).

It looks like clang somewhere promotes everything to 128-bit maths
before ultimately reducing down to 64 bit for grub_size_t. I think
this is because width is signed, and indeed converting width to an
unsigned int makes the problem go away.

This conversion also makes more sense generally:
  - the caller of all the fbfill_directN functions is
    grub_video_fb_fill_dispatch() and it takes width and height as
    unsigned ints already,
  - it doesn't make sense to fill a negative width or height.

Convert the width and height arguments and associated loop counters
to unsigned ints.

Fixes: 7ce3259f67ac (video/fb/fbfill: Fix potential integer overflow)
Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/video/fb/fbfill.c

index a37acd1e293914b82cc4338eb89c79037d7453b0..49fa16b92248a22656bf5ff8996a14d29fa0af70 100644 (file)
 static void
 grub_video_fbfill (struct grub_video_fbblit_info *dst,
                   grub_video_color_t color, int x, int y,
-                  int width, int height)
+                  unsigned int width, unsigned int height)
 {
-  int i;
-  int j;
+  unsigned int i, j;
 
   for (j = 0; j < height; j++)
     for (i = 0; i < width; i++)
@@ -53,10 +52,9 @@ grub_video_fbfill (struct grub_video_fbblit_info *dst,
 static void
 grub_video_fbfill_direct32 (struct grub_video_fbblit_info *dst,
                            grub_video_color_t color, int x, int y,
-                           int width, int height)
+                           unsigned int width, unsigned int height)
 {
-  int i;
-  int j;
+  unsigned int i, j;
   grub_uint32_t *dstptr;
   grub_size_t rowskip;
 
@@ -84,10 +82,9 @@ grub_video_fbfill_direct32 (struct grub_video_fbblit_info *dst,
 static void
 grub_video_fbfill_direct24 (struct grub_video_fbblit_info *dst,
                            grub_video_color_t color, int x, int y,
-                           int width, int height)
+                           unsigned int width, unsigned int height)
 {
-  int i;
-  int j;
+  unsigned int i, j;
   grub_size_t rowskip;
   grub_uint8_t *dstptr;
 #ifndef GRUB_CPU_WORDS_BIGENDIAN
@@ -127,10 +124,9 @@ grub_video_fbfill_direct24 (struct grub_video_fbblit_info *dst,
 static void
 grub_video_fbfill_direct16 (struct grub_video_fbblit_info *dst,
                            grub_video_color_t color, int x, int y,
-                           int width, int height)
+                           unsigned int width, unsigned int height)
 {
-  int i;
-  int j;
+  unsigned int i, j;
   grub_size_t rowskip;
   grub_uint16_t *dstptr;
 
@@ -158,10 +154,9 @@ grub_video_fbfill_direct16 (struct grub_video_fbblit_info *dst,
 static void
 grub_video_fbfill_direct8 (struct grub_video_fbblit_info *dst,
                           grub_video_color_t color, int x, int y,
-                          int width, int height)
+                          unsigned int width, unsigned int height)
 {
-  int i;
-  int j;
+  unsigned int i, j;
   grub_size_t rowskip;
   grub_uint8_t *dstptr;
   grub_uint8_t fill = (grub_uint8_t)color & 0xFF;