public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/19495] New: basic_string::_M_rep() can produce an unnaturally aligned pointer to _Rep
@ 2005-01-18  5:15 bje at gcc dot gnu dot org
  2005-01-18  9:18 ` [Bug libstdc++/19495] " pcarlini at suse dot de
                   ` (27 more replies)
  0 siblings, 28 replies; 33+ messages in thread
From: bje at gcc dot gnu dot org @ 2005-01-18  5:15 UTC (permalink / raw)
  To: gcc-bugs

basic_string.h says:

  /*
   * [...]
   *  Where the _M_p points to the first character in the string, and
   *  you cast it to a pointer-to-_Rep and subtract 1 to get a
   *  pointer to the header.
   * [...]
   */

The test case `testsuite/ext/array_allocator/2.cc' illustrates the bug.  After
linking, the global variable `extern_array' is located at an odd-numbered
address (which is fine; it is a char array).

When _M_rep() is called by basic_string's destructor, a _Rep* is returned that
is unaligned for calling _Rep methods like dispose(), because an odd-numbered
address minus 1*sizeof (_Rep) is still odd-numbered:
      _Rep*
      _M_rep() const
      { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }

This method call:
      ~basic_string()
      { _M_rep()->_M_dispose(this->get_allocator()); }

induces a bus error on architectures where misalignment triggers a bus error. 
Is this a libstdc++ bug or a documentation omission?

-- 
           Summary: basic_string::_M_rep() can produce an unnaturally
                    aligned pointer to _Rep
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bje at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: powerpc-linux
GCC target triplet: powerpc-linux


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


^ permalink raw reply	[flat|nested] 33+ messages in thread
[parent not found: <bug-19495-602@http.gcc.gnu.org/bugzilla/>]
[parent not found: <bug-19495-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2023-11-08 12:35 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-18  5:15 [Bug libstdc++/19495] New: basic_string::_M_rep() can produce an unnaturally aligned pointer to _Rep bje at gcc dot gnu dot org
2005-01-18  9:18 ` [Bug libstdc++/19495] " pcarlini at suse dot de
2005-01-18  9:35 ` pcarlini at suse dot de
2005-01-18  9:46 ` pcarlini at suse dot de
2005-01-18  9:54 ` pcarlini at suse dot de
2005-01-19  6:05 ` bje at au1 dot ibm dot com
2005-01-19  6:28 ` amodra at bigpond dot net dot au
2005-01-19  9:11 ` pcarlini at suse dot de
2005-01-19 10:06 ` pcarlini at suse dot de
2005-01-19 11:52 ` pcarlini at suse dot de
2005-01-19 15:57 ` gdr at integrable-solutions dot net
2005-01-19 16:02 ` gdr at integrable-solutions dot net
2005-01-20  0:35 ` pcarlini at suse dot de
2005-01-20  4:08 ` gdr at integrable-solutions dot net
2005-01-21 12:11 ` pcarlini at suse dot de
2005-01-21 15:23 ` ncm-nospam at cantrip dot org
2005-01-21 15:37 ` ncm-nospam at cantrip dot org
2005-01-21 15:41 ` pcarlini at suse dot de
2005-01-21 15:43 ` pcarlini at suse dot de
2005-01-21 15:45 ` pcarlini at suse dot de
2005-01-21 16:39 ` ncm-nospam at cantrip dot org
2005-02-09 14:41 ` pcarlini at suse dot de
2005-02-10  0:27 ` pinskia at gcc dot gnu dot org
2005-02-10  6:07 ` janis at gcc dot gnu dot org
2005-04-01 11:42 ` pcarlini at suse dot de
2005-04-01 13:24 ` ncm at cantrip dot org
2005-04-01 13:31 ` pcarlini at suse dot de
2005-05-18 22:11 ` cvs-commit at gcc dot gnu dot org
2005-05-28 22:27 ` cvs-commit at gcc dot gnu dot org
     [not found] <bug-19495-602@http.gcc.gnu.org/bugzilla/>
2009-05-14  2:55 ` bje at gcc dot gnu dot org
     [not found] <bug-19495-4@http.gcc.gnu.org/bugzilla/>
2015-03-23 13:25 ` redi at gcc dot gnu.org
2023-11-08 12:32 ` redi at gcc dot gnu.org
2023-11-08 12:35 ` redi at gcc dot gnu.org

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).