[gnumeric] nlsolve: minor safety added.



commit 6c2c4fd32064fd13dbfd378c284a623a866524ff
Author: Morten Welinder <terra gnome org>
Date:   Mon May 31 19:31:03 2010 -0400

    nlsolve: minor safety added.

 plugins/nlsolve/ChangeLog     |    5 +++++
 plugins/nlsolve/gnm-nlsolve.c |    8 ++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/plugins/nlsolve/ChangeLog b/plugins/nlsolve/ChangeLog
index 08002f5..cc093b6 100644
--- a/plugins/nlsolve/ChangeLog
+++ b/plugins/nlsolve/ChangeLog
@@ -1,3 +1,8 @@
+2010-05-31  Morten Welinder  <terra gnome org>
+
+	* gnm-nlsolve.c (rosenbrock_iter): Add safety against
+	non-determinisitic object functions.
+
 2010-05-30  Morten Welinder <terra gnome org>
 
 	* Release 1.10.5
diff --git a/plugins/nlsolve/gnm-nlsolve.c b/plugins/nlsolve/gnm-nlsolve.c
index 2cba648..32518f0 100644
--- a/plugins/nlsolve/gnm-nlsolve.c
+++ b/plugins/nlsolve/gnm-nlsolve.c
@@ -406,6 +406,7 @@ rosenbrock_iter (GnmNlsolve *nl)
 	int dones = 0;
 	gnm_float ykm1 = nl->yk, *xkm1;
 	gnm_float eps = gnm_pow2 (-16);
+	int safety = 0;
 
 	if (nl->tentative) {
 		nl->tentative--;
@@ -445,6 +446,13 @@ rosenbrock_iter (GnmNlsolve *nl)
 	state = g_new0 (char, n);
 
 	while (dones < n) {
+		/*
+		 * A safety that shouldn't get hit, but might if the function
+		 * being optimized in non-deterministic.
+		 */
+		if (safety++ > n * GNM_MANT_DIG)
+			break;
+
 		for (i = 0; i < n; i++) {
 			gnm_float y;
 



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