Compare commits

...

3 Commits

Author SHA1 Message Date
Dirk Hohndel
4054a19ffb cleanup: initialize all fields
This doesn't appear likely to cause an issue, but also doesn't
seem wrong.

Fixes CID 350734

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-25 11:10:31 -07:00
Dirk Hohndel
54026edf7a cleanup: fix over-eager Coverity warnings
Technically get_dive() could return a nullptr. The existing code made sure the
argument passed to get_dive() was one that always would result in a valid dive
pointer being returned. The new code is only slightly less efficient but allows
a static code analysis to easily see that we don't derefence NULL pointers here.

On some level this change is unnecessary. But it's also not wrong.

Fixes CID 354762

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-25 11:10:31 -07:00
Dirk Hohndel
a64787f70d cleanup: fix over-eager Coverity warnings
Technically get_dive(i) could return a nullptr. But given the range for i that
can never happen. Still, the test is extremely cheap and doesn't hurt.

Fixes CID 354768
Fixes CID 354766

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-25 11:10:31 -07:00
3 changed files with 9 additions and 3 deletions

View File

@ -554,6 +554,8 @@ int parse_txt_file(const char *filename, const char *csv, struct dive_table *tab
cyl.type.description = "3l Mk6";
cyl.gasmix.o2.permille = 1000;
cyl.manually_added = true;
cyl.bestmix_o2 = 0;
cyl.bestmix_he = 0;
add_cloned_cylinder(&dive->cylinders, cyl);
cyl.cylinder_use = DILUENT;

View File

@ -74,10 +74,12 @@ bool is_trip_before_after(const struct dive *dive, bool before)
{
int idx = get_idx_by_uniq_id(dive->id);
if (before) {
if (idx > 0 && get_dive(idx - 1)->divetrip)
const struct dive *d = get_dive(idx - 1);
if (d && d->divetrip)
return true;
} else {
if (idx < dive_table.nr - 1 && get_dive(idx + 1)->divetrip)
const struct dive *d = get_dive(idx + 1);
if (d && d->divetrip)
return true;
}
return false;

View File

@ -716,6 +716,8 @@ void DiveTripModelTree::populate()
uiNotification(QObject::tr("start processing"));
for (int i = 0; i < dive_table.nr; ++i) {
dive *d = get_dive(i);
if (!d) // should never happen
continue;
update_cylinder_related_info(d);
if (d->hidden_by_filter)
continue;
@ -1482,7 +1484,7 @@ void DiveTripModelList::populate()
items.reserve(dive_table.nr);
for (int i = 0; i < dive_table.nr; ++i) {
dive *d = get_dive(i);
if (d->hidden_by_filter)
if (!d || d->hidden_by_filter)
continue;
items.push_back(d);
}