summaryrefslogtreecommitdiffhomepage
path: root/qfunctionconfigurator/functionconfig.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2013-04-13 09:07:49 +0200
committerStanislaw Halik <sthalik@misaki.pl>2013-04-13 09:07:49 +0200
commitd47d6f4c89c0d20829718234881aab83d524e7c5 (patch)
treeceb5873ede3dfd33388b8c0ba77ec4e1005fd55f /qfunctionconfigurator/functionconfig.cpp
parent40786632433e0e8fe887cee243721edbdef5e8c3 (diff)
Float index rolls below zero; apply some defensive coding
Diffstat (limited to 'qfunctionconfigurator/functionconfig.cpp')
-rw-r--r--qfunctionconfigurator/functionconfig.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/qfunctionconfigurator/functionconfig.cpp b/qfunctionconfigurator/functionconfig.cpp
index 1c03aa92..c563418c 100644
--- a/qfunctionconfigurator/functionconfig.cpp
+++ b/qfunctionconfigurator/functionconfig.cpp
@@ -113,7 +113,7 @@ void FunctionConfig::reload() {
for (int k = 0; k < _points[0].x() * MEMOIZE_PRECISION; k++) {
if (k < _size)
_data[k] = _points[0].y() * k / (_points[0].x() * MEMOIZE_PRECISION);
- }
+ }
for (int i = 0; i < _points.size(); i++) {
QPointF p0 = ensureInBounds(_points, i - 1);
@@ -140,7 +140,7 @@ void FunctionConfig::reload() {
(2 * p0.y() - 5 * p1.y() + 4 * p2.y() - p3.y()) * t2 +
(-p0.y() + 3 * p1.y() - 3 * p2.y() + p3.y()) * t3);
- if (x < _size)
+ if (x >= 0 && x < _size)
_data[x] = y;
}
}
@@ -167,8 +167,11 @@ FunctionConfig::~FunctionConfig() {
//
void FunctionConfig::removePoint(int i) {
_mutex.lock();
- _points.removeAt(i);
- reload();
+ if (i >= 0 && i < _points.size())
+ {
+ _points.removeAt(i);
+ reload();
+ }
_mutex.unlock();
}
@@ -189,8 +192,11 @@ void FunctionConfig::addPoint(QPointF pt) {
//
void FunctionConfig::movePoint(int idx, QPointF pt) {
_mutex.lock();
- _points[idx] = pt;
- reload();
+ if (idx >= 0 && idx < _points.size())
+ {
+ _points[idx] = pt;
+ reload();
+ }
_mutex.unlock();
}