This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Committed] Fix uninitialized result in real_floor/real_ceil


The following "obvious" patch fixes a bug in real.c's real_floor
and real_ceil functions when VOIDmode is specified, i.e. when
these functions don't coerce their result to a specific floating
point type/format.  The problem is under these (admittedly rare)
circumstances, we fail to assign the result before returning.
Found by visual inspection.

The following patch has been tested on i686-pc-linux-gnu with a
full "make bootstrap", all default languages, and regression tested
with a top-level "make -k check" with no new failures.

Committed to mainline CVS.


2005-01-20  Roger Sayle  <roger@eyesopen.com>

        * real.c (real_floor): Don't leave the result uninitialized when
        mode is VOIDMode, but return the unrounded intermediate value.


Index: real.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/real.c,v
retrieving revision 1.148
diff -c -3 -p -r1.148 real.c
*** real.c	9 Dec 2004 20:21:45 -0000	1.148
--- real.c	20 Jan 2005 03:52:44 -0000
*************** real_floor (REAL_VALUE_TYPE *r, enum mac
*** 4625,4630 ****
--- 4625,4632 ----
      do_add (&t, &t, &dconstm1, 0);
    if (mode != VOIDmode)
      real_convert (r, mode, &t);
+   else
+     *r = t;
  }

  /* Round X to the smallest integer not less then argument, i.e. round
*************** real_ceil (REAL_VALUE_TYPE *r, enum mach
*** 4641,4646 ****
--- 4643,4650 ----
      do_add (&t, &t, &dconst1, 0);
    if (mode != VOIDmode)
      real_convert (r, mode, &t);
+   else
+     *r = t;
  }

  /* Round X to the nearest integer, but round halfway cases away from


Roger
--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]