public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ppluzhnikov at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/46830] New: s.swap(s) triggers overlapped memcpy() for versa_string
Date: Tue, 07 Dec 2010 01:49:00 -0000 [thread overview]
Message-ID: <bug-46830-4@http.gcc.gnu.org/bugzilla/> (raw)
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(),
next reply other threads:[~2010-12-07 1:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-07 1:49 ppluzhnikov at google dot com [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-46830-4@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).