From: Vladimir Serbinenko Date: Sat, 26 Oct 2013 00:57:37 +0000 (+0200) Subject: Remove all signed divisions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=739b4717259f020686e7cf1c8c409d05ce07bfa9;p=thirdparty%2Fgrub.git Remove all signed divisions --- diff --git a/grub-core/gfxmenu/gui_circular_progress.c b/grub-core/gfxmenu/gui_circular_progress.c index 284a75a5e..400df2671 100644 --- a/grub-core/gfxmenu/gui_circular_progress.c +++ b/grub-core/gfxmenu/gui_circular_progress.c @@ -36,8 +36,8 @@ struct grub_gui_circular_progress int visible; int start; int end; - int value; - int num_ticks; + unsigned value; + unsigned num_ticks; int start_angle; int ticks_disappear; char *theme_dir; @@ -238,7 +238,12 @@ parse_angle (const char *value) /* Unicode symbol of degrees (a circle, U+b0). Put here in UTF-8 to avoid potential problem with text file reesncoding */ || grub_strcmp (ptr, "\xc2\xb0") == 0) - angle = (angle * 64 + 45) / 90; + { + if (angle >= 0) + angle = ((unsigned) angle * 64 + 45) / 90; + else + angle = -((unsigned) -angle * 64 + 45) / 90; + } return angle; } diff --git a/grub-core/gfxmenu/gui_list.c b/grub-core/gfxmenu/gui_list.c index 5f7f47a43..6a0c0f8ab 100644 --- a/grub-core/gfxmenu/gui_list.c +++ b/grub-core/gfxmenu/gui_list.c @@ -271,14 +271,14 @@ draw_scrollbar (list_impl_t self, tracklen += thumb_vertical_pad; tracktop -= thumb->get_top_pad (thumb); } - int thumby = tracktop + tracklen * (value - min) / (max - min); - int thumbheight = tracklen * extent / (max - min) + 1; + int thumby = tracktop + tracklen * (value - min) / (unsigned) (max - min); + int thumbheight = tracklen * extent / (unsigned) (max - min) + 1; /* Rare occasion: too many entries or too low height. */ if (thumbheight < thumb_vertical_pad) { thumbheight = thumb_vertical_pad; thumby = tracktop + ((tracklen - thumb_vertical_pad) * (value - min) - / (max - extent)); + / (unsigned)(max - extent)); } int thumbx = frame->get_left_pad (frame); int thumbwidth = scrollbar_width - frame_horizontal_pad; diff --git a/grub-core/gfxmenu/gui_progress_bar.c b/grub-core/gfxmenu/gui_progress_bar.c index 588f23f10..8f6221e9c 100644 --- a/grub-core/gfxmenu/gui_progress_bar.c +++ b/grub-core/gfxmenu/gui_progress_bar.c @@ -170,7 +170,7 @@ draw_pixmap_bar (grub_gui_progress_bar_t self) hlheight -= hl_v_pad; barwidth = (tracklen * (self->value - self->start) - / (self->end - self->start)); + / (unsigned) (self->end - self->start)); if (barwidth >= hl_h_pad) { diff --git a/grub-core/lib/libgcrypt/mpi/longlong.h b/grub-core/lib/libgcrypt/mpi/longlong.h index 5dba7931a..8aeb60e1c 100644 --- a/grub-core/lib/libgcrypt/mpi/longlong.h +++ b/grub-core/lib/libgcrypt/mpi/longlong.h @@ -170,7 +170,7 @@ MA 02111-1307, USA. */ (pl) = __m0 * __m1; \ } while (0) #define UMUL_TIME 46 -#ifndef LONGLONG_STANDALONE +#if 0 #define udiv_qrnnd(q, r, n1, n0, d) \ do { UDItype __r; \ (q) = __udiv_qrnnd (&__r, (n1), (n0), (d)); \ @@ -353,7 +353,7 @@ extern UDItype __udiv_qrnnd (); #define UMUL_TIME 40 #define UDIV_TIME 80 #endif -#ifndef LONGLONG_STANDALONE +#if 0 #define udiv_qrnnd(q, r, n1, n0, d) \ do { USItype __r; \ (q) = __udiv_qrnnd (&__r, (n1), (n0), (d)); \ @@ -1294,7 +1294,7 @@ typedef unsigned int UTItype __attribute__ ((mode (TI))); #define UMUL_TIME 39 /* 39 instructions */ #endif #ifndef udiv_qrnnd -#ifndef LONGLONG_STANDALONE +#if 0 #define udiv_qrnnd(q, r, n1, n0, d) \ do { USItype __r; \ (q) = __udiv_qrnnd (&__r, (n1), (n0), (d)); \ diff --git a/grub-core/lib/libgcrypt/mpi/mpi-pow.c b/grub-core/lib/libgcrypt/mpi/mpi-pow.c index 33bbebe32..e73632570 100644 --- a/grub-core/lib/libgcrypt/mpi/mpi-pow.c +++ b/grub-core/lib/libgcrypt/mpi/mpi-pow.c @@ -75,9 +75,6 @@ gcry_mpi_powm (gcry_mpi_t res, rp = res->d; ep = expo->d; - if (!msize) - msize = 1 / msize; /* Provoke a signal. */ - if (!esize) { /* Exponent is zero, result is 1 mod MOD, i.e., 1 or 0 depending diff --git a/grub-core/lib/libgcrypt/mpi/mpih-div.c b/grub-core/lib/libgcrypt/mpi/mpih-div.c index 224b81086..ef9bf5955 100644 --- a/grub-core/lib/libgcrypt/mpi/mpih-div.c +++ b/grub-core/lib/libgcrypt/mpi/mpih-div.c @@ -214,7 +214,7 @@ _gcry_mpih_divrem( mpi_ptr_t qp, mpi_size_t qextra_limbs, case 0: /* We are asked to divide by zero, so go ahead and do it! (To make the compiler not remove this statement, return the value.) */ - return 1 / dsize; + return 0;//1 / dsize; case 1: { diff --git a/grub-core/normal/datetime.c b/grub-core/normal/datetime.c index 2b0faca90..dcbca79e8 100644 --- a/grub-core/normal/datetime.c +++ b/grub-core/normal/datetime.c @@ -40,7 +40,8 @@ grub_get_weekday (struct grub_datetime *datetime) y = datetime->year - a; m = datetime->month + 12 * a - 2; - return (datetime->day + y + y / 4 - y / 100 + y / 400 + (31 * m / 12)) % 7; + return ((unsigned)(datetime->day + y + y / 4 - y / 100 + y / 400 + + (31 * m / 12))) % 7; } const char * diff --git a/grub-core/term/tparm.c b/grub-core/term/tparm.c index 8c1c288a0..33cf04e03 100644 --- a/grub-core/term/tparm.c +++ b/grub-core/term/tparm.c @@ -614,13 +614,13 @@ tparam_internal(const char *string, va_list ap) case '/': y = npop(); x = npop(); - npush(y ? (x / y) : 0); + npush(y ? ((unsigned) x / (unsigned) y) : 0); break; case 'm': y = npop(); x = npop(); - npush(y ? (x % y) : 0); + npush(y ? ((unsigned) x % (unsigned) y) : 0); break; case 'A': diff --git a/include/grub/gui.h b/include/grub/gui.h index 6f818627e..de402b776 100644 --- a/include/grub/gui.h +++ b/include/grub/gui.h @@ -123,13 +123,27 @@ typedef signed grub_fixed_signed_t; static inline signed grub_fixed_sfs_divide (signed a, grub_fixed_signed_t b) { - return (a * GRUB_FIXED_1) / b; + if (b < 0) + { + b = -b; + a = -a; + } + if (a < 0) + return -((unsigned) a * GRUB_FIXED_1) / (unsigned) b; + return ((unsigned) a * GRUB_FIXED_1) / (unsigned) b; } static inline grub_fixed_signed_t grub_fixed_fsf_divide (grub_fixed_signed_t a, signed b) { - return a / b; + if (b < 0) + { + b = -b; + a = -a; + } + if (a < 0) + return -(unsigned) a / (unsigned) b; + return (unsigned) a / (unsigned) b; } static inline signed