mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Consistently use for_each_dive (and use it correctly)
The way the macro is written there is no need to test the dive against NULL before dereferencing. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
b303f217a9
commit
09e7c61fee
5 changed files with 17 additions and 25 deletions
|
@ -706,8 +706,7 @@ void DiveListView::deleteDive()
|
||||||
// so instead of using the for_each_dive macro I'm using an explicit for loop
|
// so instead of using the for_each_dive macro I'm using an explicit for loop
|
||||||
// to make this easier to understand
|
// to make this easier to understand
|
||||||
int lastDiveNr = -1;
|
int lastDiveNr = -1;
|
||||||
for (i = 0; i < dive_table.nr; i++) {
|
for_each_dive (i, d) {
|
||||||
d = get_dive(i);
|
|
||||||
if (!d->selected)
|
if (!d->selected)
|
||||||
continue;
|
continue;
|
||||||
delete_single_dive(i);
|
delete_single_dive(i);
|
||||||
|
|
|
@ -270,10 +270,8 @@ void MainTab::enableEdition(EditMode newEditMode)
|
||||||
|
|
||||||
// We may be editing one or more dives here. backup everything.
|
// We may be editing one or more dives here. backup everything.
|
||||||
struct dive *mydive;
|
struct dive *mydive;
|
||||||
for (int i = 0; i < dive_table.nr; i++) {
|
int i;
|
||||||
mydive = get_dive(i);
|
for_each_dive(i, mydive) {
|
||||||
if (!mydive)
|
|
||||||
continue;
|
|
||||||
if (!mydive->selected)
|
if (!mydive->selected)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -596,14 +594,12 @@ void MainTab::reload()
|
||||||
#define EDIT_SELECTED_DIVES(WHAT) \
|
#define EDIT_SELECTED_DIVES(WHAT) \
|
||||||
do { \
|
do { \
|
||||||
struct dive *mydive = NULL; \
|
struct dive *mydive = NULL; \
|
||||||
|
int _i; \
|
||||||
if (editMode == NONE) \
|
if (editMode == NONE) \
|
||||||
return; \
|
return; \
|
||||||
\
|
\
|
||||||
for (int _i = 0; _i < dive_table.nr; _i++) { \
|
for_each_dive (_i, mydive) { \
|
||||||
mydive = get_dive(_i); \
|
if (!mydive->selected || mydive == current_dive) \
|
||||||
if (!mydive || mydive == current_dive)\
|
|
||||||
continue; \
|
|
||||||
if (!mydive->selected) \
|
|
||||||
continue; \
|
continue; \
|
||||||
\
|
\
|
||||||
WHAT; \
|
WHAT; \
|
||||||
|
@ -836,10 +832,8 @@ void MainTab::rejectChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dive *mydive;
|
struct dive *mydive;
|
||||||
for (int i = 0; i < dive_table.nr; i++) {
|
int i;
|
||||||
mydive = get_dive(i);
|
for_each_dive (i, mydive) {
|
||||||
if (!mydive)
|
|
||||||
continue;
|
|
||||||
if (!mydive->selected)
|
if (!mydive->selected)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,9 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* walk the dive list in chronological order */
|
/* walk the dive list in chronological order */
|
||||||
for (int i = 0; i < dive_table.nr; i++) {
|
int i;
|
||||||
|
struct dive *dive;
|
||||||
|
for_each_dive(i, dive) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char filename[PATH_MAX];
|
char filename[PATH_MAX];
|
||||||
int streamsize;
|
int streamsize;
|
||||||
|
@ -145,9 +147,6 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
|
||||||
* Get the i'th dive in XML format so we can process it.
|
* Get the i'th dive in XML format so we can process it.
|
||||||
* We need to save to a file before we can reload it back into memory...
|
* We need to save to a file before we can reload it back into memory...
|
||||||
*/
|
*/
|
||||||
struct dive *dive = get_dive(i);
|
|
||||||
if (!dive)
|
|
||||||
continue;
|
|
||||||
if (selected && !dive->selected)
|
if (selected && !dive->selected)
|
||||||
continue;
|
continue;
|
||||||
f = tmpfile();
|
f = tmpfile();
|
||||||
|
|
|
@ -131,8 +131,7 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive)
|
||||||
|
|
||||||
/* this relies on the fact that the dives in the dive_table
|
/* this relies on the fact that the dives in the dive_table
|
||||||
* are in chronological order */
|
* are in chronological order */
|
||||||
for (idx = 0; idx < dive_table.nr; idx++) {
|
for_each_dive (idx, dp) {
|
||||||
dp = dive_table.dives[idx];
|
|
||||||
if (dive && dp->when == dive->when) {
|
if (dive && dp->when == dive->when) {
|
||||||
/* that's the one we are showing */
|
/* that's the one we are showing */
|
||||||
if (idx > 0)
|
if (idx > 0)
|
||||||
|
@ -230,10 +229,10 @@ static void get_ranges(char *buffer, int size)
|
||||||
{
|
{
|
||||||
int i, len;
|
int i, len;
|
||||||
int first = -1, last = -1;
|
int first = -1, last = -1;
|
||||||
|
struct dive *dive;
|
||||||
|
|
||||||
snprintf(buffer, size, "%s", translate("gettextFromC", "for dives #"));
|
snprintf(buffer, size, "%s", translate("gettextFromC", "for dives #"));
|
||||||
for (i = 0; i < dive_table.nr; i++) {
|
for_each_dive (i, dive) {
|
||||||
struct dive *dive = get_dive(i);
|
|
||||||
if (!dive->selected)
|
if (!dive->selected)
|
||||||
continue;
|
continue;
|
||||||
if (dive->number < 1) {
|
if (dive->number < 1) {
|
||||||
|
|
|
@ -793,8 +793,9 @@ static char *uemis_get_divenr(char *deviceidstr)
|
||||||
char divenr[10];
|
char divenr[10];
|
||||||
|
|
||||||
deviceid = atoi(deviceidstr);
|
deviceid = atoi(deviceidstr);
|
||||||
for (i = 0; i < dive_table.nr; i++) {
|
struct dive *d;
|
||||||
struct divecomputer *dc = &dive_table.dives[i]->dc;
|
for_each_dive (i, d) {
|
||||||
|
struct divecomputer *dc = &d->dc;
|
||||||
while (dc) {
|
while (dc) {
|
||||||
if (dc->model && !strcmp(dc->model, "Uemis Zurich") &&
|
if (dc->model && !strcmp(dc->model, "Uemis Zurich") &&
|
||||||
(dc->deviceid == 0 || dc->deviceid == 0x7fffffff || dc->deviceid == deviceid) &&
|
(dc->deviceid == 0 || dc->deviceid == 0x7fffffff || dc->deviceid == deviceid) &&
|
||||||
|
|
Loading…
Add table
Reference in a new issue