From 609db520ecc18c316c9e8762d02be10ce77c6e08 Mon Sep 17 00:00:00 2001 From: tweenk Date: Sat, 21 Feb 2009 02:38:12 +0000 Subject: [PATCH] Fix aliasing rules violation in glib-list-iterators.h --- src/util/glib-list-iterators.h | 39 +++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/util/glib-list-iterators.h b/src/util/glib-list-iterators.h index 586bc314a..3779cad1e 100644 --- a/src/util/glib-list-iterators.h +++ b/src/util/glib-list-iterators.h @@ -1,11 +1,14 @@ -/* - * Inkscape::Util::GSListIterator - STL iterator for GSList +/** @file + * @brief STL iterators for Glib list types + */ +/* Inkscape::Util::GSListIterator - STL iterator for GSList * Inkscape::Util::GSListConstIterator - STL iterator for GSList * Inkscape::Util::GListIterator - STL iterator for GList * Inkscape::Util::GListConstIterator - STL iterator for GList * * Authors: * MenTaLguY + * Krzysztof Kosiński * * Copyright (C) 2005 MenTaLguY * @@ -21,7 +24,6 @@ #include "glib/glist.h" namespace Inkscape { - namespace Util { template class GSListConstIterator; @@ -44,7 +46,9 @@ public: GSList const *list() const { return _list; } reference operator*() const { - return *reinterpret_cast(&_list->data); + _ref_union u; + u._gp = _list->data; + return *u._p; } bool operator==(GSListConstIterator const &other) { @@ -65,6 +69,7 @@ public: } private: + union _ref_union {gpointer _gp; pointer _p;}; GSList const *_list; }; @@ -86,10 +91,12 @@ public: GSList *list() { return _list; } const_reference operator*() const { - return *reinterpret_cast(&_list->data); + return const_cast *>(this)->operator*(); } reference operator*() { - return *reinterpret_cast(&_list->data); + _ref_union u; + u._gp = _list->data; + return *u._p; } bool operator==(GSListIterator const &other) { @@ -110,6 +117,7 @@ public: } private: + union _ref_union {gpointer _gp; pointer _p;}; GSList *_list; }; @@ -128,7 +136,9 @@ public: GList const *list() const { return _list; } reference operator*() const { - return *reinterpret_cast(&_list->data); + _ref_union u; + u._gp = _list->data; + return *u._p; } bool operator==(GListConstIterator const &other) { @@ -159,6 +169,7 @@ public: } private: + union _ref_union {gpointer _gp; pointer _p;}; GList const *_list; }; @@ -186,9 +197,13 @@ public: GList *list() { return _list; } const_reference operator*() const { - return *reinterpret_cast(&_list->data); + return const_cast *>(this)->operator*(); + } + reference operator*() { + _ref_union u; + u._gp = _list->data; + return *u._p; } - reference operator*() { return *reinterpret_cast(&_list->data); } bool operator==(GListIterator const &other) { return other._list == _list; @@ -218,12 +233,12 @@ public: } private: + union _ref_union {gpointer _gp; pointer _p;}; GList *_list; }; -} - -} +} // namespace Util +} // Namespace Inkscape #endif /* -- 2.30.2