* mln/data/memset_.hh (mln::data::impl::memset): Here.
---
milena/ChangeLog | 6 ++++++
milena/mln/data/memset_.hh | 16 ++++++++++++----
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index fc516e7..4caaa0a 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,11 @@
2009-10-06 Roland Levillain <roland(a)lrde.epita.fr>
+ Honor strict-aliasing rules in memset_.
+
+ * mln/data/memset_.hh (mln::data::impl::memset): Here.
+
+2009-10-06 Roland Levillain <roland(a)lrde.epita.fr>
+
Warn about a bug in memcpy_ with g++ 4.2 on Debian for IA-32.
* mln/data/memcpy_.hh (mln::data::impl::memcpy_): Here.
diff --git a/milena/mln/data/memset_.hh b/milena/mln/data/memset_.hh
index 4559e05..42b1412 100644
--- a/milena/mln/data/memset_.hh
+++ b/milena/mln/data/memset_.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -101,9 +102,16 @@ namespace mln
if (sizeof(mln_value(I)) == 1)
{
- std::memset((void*)(& pix.val()),
- *(const int*)(&v), // violent cast
- n);
+ /* Because of strict-aliasing rules, we cannot use
+
+ *(const int*)(&v)
+
+ as second argument for std::memset. Hence the use of
+ std::memcpy. See the `-fstrict-aliasing' entry in GCC's
+ documentation for more information. */
+ char c;
+ std::memcpy(&c, &v, 1);
+ std::memset((void*)(& pix.val()), c, n);
}
else
{
--
1.6.3.1
Show replies by date