QML UI: further validation in the C++ code

Don't allow negative depth or depth beyond 500m.

Additional checks that the gas mix is possible (even thought QML code
SHOULD only allow valid combinations).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2016-02-20 22:11:03 -08:00
parent a550467e8b
commit 5da9486533

View file

@ -476,13 +476,19 @@ QString QMLManager::commitChanges(QString diveId, QString date, QString location
d->dc.duration.seconds = d->duration.seconds = h * 3600 + m * 60 + s; d->dc.duration.seconds = d->duration.seconds = h * 3600 + m * 60 + s;
} }
if (get_depth_string(d->maxdepth.mm, true, true) != depth) { if (get_depth_string(d->maxdepth.mm, true, true) != depth) {
diveChanged = true; int depthValue = parseLengthToMm(depth);
d->maxdepth.mm = parseLengthToMm(depth); // the QML code should stop negative depth, but massively huge depth can make
if (same_string(d->dc.model, "manually added dive")) { // the profile extremely slow or even run out of memory and crash, so keep
d->dc.maxdepth.mm = d->maxdepth.mm; // the depth <= 500m
free(d->dc.sample); if (0 <= depthValue && depthValue <= 500000) {
d->dc.sample = 0; diveChanged = true;
d->dc.samples = 0; d->maxdepth.mm = depthValue;
if (same_string(d->dc.model, "manually added dive")) {
d->dc.maxdepth.mm = d->maxdepth.mm;
free(d->dc.sample);
d->dc.sample = 0;
d->dc.samples = 0;
}
} }
} }
if (get_temperature_string(d->airtemp, true) != airtemp) { if (get_temperature_string(d->airtemp, true) != airtemp) {
@ -509,9 +515,16 @@ QString QMLManager::commitChanges(QString diveId, QString date, QString location
} }
// gasmix for first cylinder // gasmix for first cylinder
if (get_gas_string(d->cylinder[0].gasmix) != gasmix) { if (get_gas_string(d->cylinder[0].gasmix) != gasmix) {
diveChanged = true; int o2 = parseGasMixO2(gasmix);
d->cylinder[0].gasmix.o2.permille = parseGasMixO2(gasmix); int he = parseGasMixHE(gasmix);
d->cylinder[0].gasmix.he.permille = parseGasMixHE(gasmix); // the QML code SHOULD only accept valid gas mixes, but just to make sure
if (o2 >= 0 && o2 <= 100 &&
he >= 0 && he <= 100 &&
o2 + he <= 100) {
diveChanged = true;
d->cylinder[0].gasmix.o2.permille = o2;
d->cylinder[0].gasmix.he.permille = he;
}
} }
if (!same_string(d->suit, qPrintable(suit))) { if (!same_string(d->suit, qPrintable(suit))) {
diveChanged = true; diveChanged = true;