public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/46830] New: s.swap(s) triggers overlapped memcpy() for versa_string
@ 2010-12-07  1:49 ppluzhnikov at google dot com
  2010-12-07  2:14 ` [Bug libstdc++/46830] " paolo.carlini at oracle dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ppluzhnikov at google dot com @ 2010-12-07  1:49 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46830

           Summary: s.swap(s) triggers overlapped memcpy() for
                    versa_string
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ppluzhnikov@google.com


Consider this test case:

//--- cut ---
#include <ext/vstring.h>
#include <ext/vstring_fwd.h>

typedef __gnu_cxx::__vstring string;

int main()
{
  string s = "Hello";
  s.swap(s);
}
//--- cut ---

When built with current GCC SVN (rev 167521), and run under Valgrind,
it produces:

==21887== Source and destination overlap in memcpy(0x7ffefff390, 0x7ffefff390,
16)
==21887==    at 0x4C2C364: memcpy (valgrind/memcheck/mc_replace_strmem.c:523)
==21887==    by 0x400B92: std::char_traits<char>::copy(char*, char const*,
unsigned long)
(/t/gcc-svn-install/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/bits/char_traits.h:268)
==21887==    by 0x400DD4: __gnu_cxx::__sso_string_base<char,
std::char_traits<char>, std::allocator<char>
>::_M_swap(__gnu_cxx::__sso_string_base<char, std::char_traits<char>,
std::allocator<char> >&)
(/t/gcc-svn-install/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/ext/sso_string_base.h:248)
==21887==    by 0x400C20: __gnu_cxx::__versa_string<char,
std::char_traits<char>, std::allocator<char>,
__gnu_cxx::__sso_string_base>::swap(__gnu_cxx::__versa_string<char,
std::char_traits<char>, std::allocator<char>, __gnu_cxx::__sso_string_base>&)
(/t/gcc-svn-install/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/ext/vstring.h:1475)
==21887==    by 0x400ACC: main (/g/tmp/t.cc:9)

I can't find any prohibition in C++ standards on calling s.swap(s),
nor any indication in POSIX standards that memcpy(p, p, ...) is allowed.

Proposed fix:

Index: libstdc++-v3/include/ext/sso_string_base.h
===================================================================
--- libstdc++-v3/include/ext/sso_string_base.h  (revision 167521)
+++ libstdc++-v3/include/ext/sso_string_base.h  (working copy)
@@ -232,6 +232,9 @@
     __sso_string_base<_CharT, _Traits, _Alloc>::
     _M_swap(__sso_string_base& __rcs)
     {
+      if (this == &__rcs)
+       return;
+
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // 431. Swapping containers with unequal allocators.
       std::__alloc_swap<_CharT_alloc_type>::_S_do_it(_M_get_allocator(),


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/46830] s.swap(s) triggers overlapped memcpy() for versa_string
  2010-12-07  1:49 [Bug c++/46830] New: s.swap(s) triggers overlapped memcpy() for versa_string ppluzhnikov at google dot com
@ 2010-12-07  2:14 ` paolo.carlini at oracle dot com
  2010-12-07  2:43 ` paolo at gcc dot gnu.org
  2010-12-07  2:45 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-12-07  2:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46830

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2010.12.07 02:14:39
          Component|c++                         |libstdc++
         AssignedTo|unassigned at gcc dot       |paolo.carlini at oracle dot
                   |gnu.org                     |com
   Target Milestone|---                         |4.6.0
     Ever Confirmed|0                           |1

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-12-07 02:14:39 UTC ---
Ok, thanks. I'll run your fix through the testsuite and apply it.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/46830] s.swap(s) triggers overlapped memcpy() for versa_string
  2010-12-07  1:49 [Bug c++/46830] New: s.swap(s) triggers overlapped memcpy() for versa_string ppluzhnikov at google dot com
  2010-12-07  2:14 ` [Bug libstdc++/46830] " paolo.carlini at oracle dot com
@ 2010-12-07  2:43 ` paolo at gcc dot gnu.org
  2010-12-07  2:45 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo at gcc dot gnu.org @ 2010-12-07  2:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46830

--- Comment #2 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2010-12-07 02:43:20 UTC ---
Author: paolo
Date: Tue Dec  7 02:43:16 2010
New Revision: 167528

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167528
Log:
2010-12-06  Paul Pluzhnikov  <ppluzhnikov@google.com>

    PR libstdc++/46830
    * include/ext/sso_string_base.h (__sso_string_base<>::_M_swap):
    Early return when this == &__rcs.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/ext/sso_string_base.h


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/46830] s.swap(s) triggers overlapped memcpy() for versa_string
  2010-12-07  1:49 [Bug c++/46830] New: s.swap(s) triggers overlapped memcpy() for versa_string ppluzhnikov at google dot com
  2010-12-07  2:14 ` [Bug libstdc++/46830] " paolo.carlini at oracle dot com
  2010-12-07  2:43 ` paolo at gcc dot gnu.org
@ 2010-12-07  2:45 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-12-07  2:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46830

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-12-07 02:45:32 UTC ---
Done.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-12-07  2:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-07  1:49 [Bug c++/46830] New: s.swap(s) triggers overlapped memcpy() for versa_string ppluzhnikov at google dot com
2010-12-07  2:14 ` [Bug libstdc++/46830] " paolo.carlini at oracle dot com
2010-12-07  2:43 ` paolo at gcc dot gnu.org
2010-12-07  2:45 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).