[PATCH 1/4] dive.h: add a 'unsafe' variant of FOR_EACH_PICTURE

Lubomir I. Ivanov neolit123 at gmail.com
Tue Oct 28 04:35:13 PDT 2014


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

This prevents a warning caused by -Waddress, that the address
of 'displayed_dive' will always be defined.

We don't really want to disable this warning group as it's
*actually* useful in terms of partability. A previous,
less intrusive solution was also proposed which simply
declared a local 'struct dive' inside ::updateDivePictures()
but it was not accepted.

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---

the warning has been creeping around for 5 mounths or so, but
is overall harmless.
i don't like this change because it creates a useless interface
macro.

the other solution was cleaner:
struct dive *displayed_dive_tmp = &displayed_dive;
...
	FOR_EACH_PICTURE_UNSAFE(displayed_dive_tmp) {

comments?

on the other hand global vars shouldn't be used in such a manner.
allocating a context struct on the heap and storing everything
supposedly global in there is one way to do it properly.
---
 dive.h                      | 2 ++
 qt-ui/divepicturewidget.cpp | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/dive.h b/dive.h
index ef5ff0f..f18a3bf 100644
--- a/dive.h
+++ b/dive.h
@@ -349,6 +349,8 @@ struct picture {
 	if (_dive)              \
 		for (struct picture *picture = (_dive)->picture_list; picture; picture = picture->next)
 
+#define FOR_EACH_PICTURE_UNSAFE(_dive) \
+	for (struct picture *picture = (_dive)->picture_list; picture; picture = picture->next)
 
 extern struct picture *alloc_picture();
 extern void dive_create_picture(struct dive *d, char *filename, int shift_time);
diff --git a/qt-ui/divepicturewidget.cpp b/qt-ui/divepicturewidget.cpp
index 34f69e0..c0db49b 100644
--- a/qt-ui/divepicturewidget.cpp
+++ b/qt-ui/divepicturewidget.cpp
@@ -51,7 +51,7 @@ void DivePictureModel::updateDivePictures()
 
 	stringPixmapCache.clear();
 	QStringList pictures;
-	FOR_EACH_PICTURE (&displayed_dive) {
+	FOR_EACH_PICTURE_UNSAFE(&displayed_dive) {
 		stringPixmapCache[QString(picture->filename)].offsetSeconds = picture->offset.seconds;
 		pictures.push_back(QString(picture->filename));
 	}
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list