gnumeric r16563 - in branches/gnumeric-1-8: . src



Author: mortenw
Date: Fri May 16 15:29:30 2008
New Revision: 16563
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16563&view=rev

Log:
2008-05-15  Morten Welinder  <terra gnome org>

	* src/mathfunc.c (random_gamma): Handle overflow and bogus
	arguments.  Fixes #533288.




Modified:
   branches/gnumeric-1-8/ChangeLog
   branches/gnumeric-1-8/NEWS
   branches/gnumeric-1-8/src/mathfunc.c

Modified: branches/gnumeric-1-8/NEWS
==============================================================================
--- branches/gnumeric-1-8/NEWS	(original)
+++ branches/gnumeric-1-8/NEWS	Fri May 16 15:29:30 2008
@@ -25,6 +25,7 @@
 	* Fix problem loading Quattro Pro files.  [#530183]
 	* Fix right/center text for Quattro Pro files.
 	* Fix problem with sheet changes during range selection.  [#529309]
+	* Fix hang.  [#533288]
 
 --------------------------------------------------------------------------
 Gnumeric 1.8.2

Modified: branches/gnumeric-1-8/src/mathfunc.c
==============================================================================
--- branches/gnumeric-1-8/src/mathfunc.c	(original)
+++ branches/gnumeric-1-8/src/mathfunc.c	Fri May 16 15:29:30 2008
@@ -6804,16 +6804,17 @@
 }
 
 static gnm_float
-ran_gamma_int (unsigned int a)
+ran_gamma_int (gnm_float a)
 {
 	if (a < 12) {
 		gnm_float prod;
 
 		do {
-			unsigned int i;
+			unsigned int i, ua;
 			prod = 1;
+			ua = (unsigned int)a;
 
-			for (i = 0; i < a; i++)
+			for (i = 0; i < ua; i++)
 				prod *= random_01 ();
 
 			/*
@@ -6835,9 +6836,12 @@
 gnm_float
 random_gamma (gnm_float a, gnm_float b)
 {
-	/* assume a > 0 */
-	/* FIXME: why not simply a gnm_float?	*/
-	unsigned int na = gnm_floor (a);
+	gnm_float na;
+
+	if (gnm_isnan (a) || gnm_isnan (b) || a <= 0 || b <= 0)
+		return gnm_nan;
+
+	na = gnm_floor (a);
 
 	if (a == na)
 		return b * ran_gamma_int (na);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]