From 9850ae3c71d11961236acce7ee89ea49d3ae8208 Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Thu, 8 Sep 2016 13:14:00 +0000 Subject: [PATCH] sparse engine: consistently use delete[] when destroying solution vectors Technically, using 'plain' delete for deleting objects allocated with new[] is undefined behaviour. In practice, this didn't appear to be a problem. git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@11786 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/src/sparse/PS_JOR.cc | 2 +- prism/src/sparse/PS_NondetReachReward.cc | 2 +- prism/src/sparse/PS_NondetUntil.cc | 2 +- prism/src/sparse/PS_Power.cc | 2 +- prism/src/sparse/PS_SOR.cc | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/prism/src/sparse/PS_JOR.cc b/prism/src/sparse/PS_JOR.cc index 451ffc64..0bf2567b 100644 --- a/prism/src/sparse/PS_JOR.cc +++ b/prism/src/sparse/PS_JOR.cc @@ -300,7 +300,7 @@ jdouble omega // omega (over-relaxation parameter) PS_PrintToMainLog(env, "\n%s: %d iterations in %.2f seconds (average %.6f, setup %.2f)\n", (omega == 1.0)?"Jacobi":"JOR", iters, time_taken, time_for_iters/iters, time_for_setup); // if the iterative method didn't terminate, this is an error - if (!done) { delete soln; soln = NULL; PS_SetErrorMessage("Iterative method did not converge within %d iterations.\nConsider using a different numerical method or increasing the maximum number of iterations", iters); } + if (!done) { delete[] soln; soln = NULL; PS_SetErrorMessage("Iterative method did not converge within %d iterations.\nConsider using a different numerical method or increasing the maximum number of iterations", iters); } // catch exceptions: register error, free memory } catch (std::bad_alloc e) { diff --git a/prism/src/sparse/PS_NondetReachReward.cc b/prism/src/sparse/PS_NondetReachReward.cc index 0221a66f..cca80bd4 100644 --- a/prism/src/sparse/PS_NondetReachReward.cc +++ b/prism/src/sparse/PS_NondetReachReward.cc @@ -387,7 +387,7 @@ jboolean min // min or max probabilities (true = min, false = max) PS_PrintToMainLog(env, "\nIterative method: %d iterations in %.2f seconds (average %.6f, setup %.2f)\n", iters, time_taken, time_for_iters/iters, time_for_setup); // if the iterative method didn't terminate, this is an error - if (!done) { delete soln; soln = NULL; PS_SetErrorMessage("Iterative method did not converge within %d iterations.\nConsider using a different numerical method or increasing the maximum number of iterations", iters); } + if (!done) { delete[] soln; soln = NULL; PS_SetErrorMessage("Iterative method did not converge within %d iterations.\nConsider using a different numerical method or increasing the maximum number of iterations", iters); } // close file to store adversary (if required) if (export_adv_enabled != EXPORT_ADV_NONE) { diff --git a/prism/src/sparse/PS_NondetUntil.cc b/prism/src/sparse/PS_NondetUntil.cc index 83266187..b9ba4eb5 100644 --- a/prism/src/sparse/PS_NondetUntil.cc +++ b/prism/src/sparse/PS_NondetUntil.cc @@ -347,7 +347,7 @@ jlong _strat // strategy storage PS_PrintToMainLog(env, "\nIterative method: %d iterations in %.2f seconds (average %.6f, setup %.2f)\n", iters, time_taken, time_for_iters/iters, time_for_setup); // if the iterative method didn't terminate, this is an error - if (!done) { delete soln; soln = NULL; PS_SetErrorMessage("Iterative method did not converge within %d iterations.\nConsider using a different numerical method or increasing the maximum number of iterations", iters); } + if (!done) { delete[] soln; soln = NULL; PS_SetErrorMessage("Iterative method did not converge within %d iterations.\nConsider using a different numerical method or increasing the maximum number of iterations", iters); } // close file to store adversary (if required) if (export_adv_enabled != EXPORT_ADV_NONE) { diff --git a/prism/src/sparse/PS_Power.cc b/prism/src/sparse/PS_Power.cc index 174cbec0..dfce25ff 100644 --- a/prism/src/sparse/PS_Power.cc +++ b/prism/src/sparse/PS_Power.cc @@ -246,7 +246,7 @@ jboolean transpose // transpose A? (i.e. solve xA=x not Ax=x?) PS_PrintToMainLog(env, "\nPower method: %d iterations in %.2f seconds (average %.6f, setup %.2f)\n", iters, time_taken, time_for_iters/iters, time_for_setup); // if the iterative method didn't terminate, this is an error - if (!done) { delete soln; soln = NULL; PS_SetErrorMessage("Iterative method did not converge within %d iterations.\nConsider using a different numerical method or increasing the maximum number of iterations", iters); } + if (!done) { delete[] soln; soln = NULL; PS_SetErrorMessage("Iterative method did not converge within %d iterations.\nConsider using a different numerical method or increasing the maximum number of iterations", iters); } // catch exceptions: register error, free memory } catch (std::bad_alloc e) { diff --git a/prism/src/sparse/PS_SOR.cc b/prism/src/sparse/PS_SOR.cc index 24229293..bbb3a806 100644 --- a/prism/src/sparse/PS_SOR.cc +++ b/prism/src/sparse/PS_SOR.cc @@ -301,7 +301,7 @@ jboolean forwards // forwards or backwards? PS_PrintToMainLog(env, "\n%s%s: %d iterations in %.2f seconds (average %.6f, setup %.2f)\n", forwards?"":"Backwards ", (omega == 1.0)?"Gauss-Seidel":"SOR", iters, time_taken, time_for_iters/iters, time_for_setup); // if the iterative method didn't terminate, this is an error - if (!done) { delete soln; soln = NULL; PS_SetErrorMessage("Iterative method did not converge within %d iterations.\nConsider using a different numerical method or increasing the maximum number of iterations", iters); } + if (!done) { delete[] soln; soln = NULL; PS_SetErrorMessage("Iterative method did not converge within %d iterations.\nConsider using a different numerical method or increasing the maximum number of iterations", iters); } // catch exceptions: register error, free memory } catch (std::bad_alloc e) {