public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/60201] Issue with CRTP generation under 4.8.1
Date: Fri, 14 Feb 2014 19:44:00 -0000	[thread overview]
Message-ID: <bug-60201-4-MdvLKfU4lw@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-60201-4@http.gcc.gnu.org/bugzilla/>

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Look at the original object:
    Baseclass<Subclass<ParamOne, ParamTwo>, ParamOne, ParamTwo> test;

test is of class Baseclass.  You call Method on it.
Method then has a cast from Baseclass to Subclass for *this but *this is only
of type Baseclass and not Subclass.

So when you call SubclassMethod on the object you just casted, it would really
be only a Baseclass and not a Subclass so m_SubClassValue never was initialized
and is in fact outside of the object.

If we run using valgrind we get:
==10910== Use of uninitialised value of size 8
==10910==    at 0x56167AB: _itoa_word (_itoa.c:195)
==10910==    by 0x5619347: vfprintf (vfprintf.c:1616)
==10910==    by 0x5621A59: printf (printf.c:35)
==10910==    by 0x400740: Subclass<ParamOne, ParamTwo>::SubclassMethod(ParamOne
const&, ParamTwo&) (t.cc:60)
==10910==    by 0x4007D6: Baseclass<Subclass<ParamOne, ParamTwo>, ParamOne,
ParamTwo>::Method(ParamOne const&) (t.cc:35)
==10910==    by 0x400787: main (t.cc:71)

If we run using address sanitizer we get:
================================================================
==11676== ERROR: AddressSanitizer: stack-buffer-overflow on address
0x7fff3594a8d4 at pc 0x400a6f bp 0x7fff3594a7c0 sp 0x7fff3594a7b8
READ of size 4 at 0x7fff3594a8d4 thread T0
    #0 0x400a6e (/home/apinski/a.out+0x400a6e)
    #1 0x400cdd (/home/apinski/a.out+0x400cdd)
    #2 0x400bc8 (/home/apinski/a.out+0x400bc8)
    #3 0x7fe47a7b9c8c (/lib/libc-2.11.3.so+0x1ec8c)
    #4 0x4008d8 (/home/apinski/a.out+0x4008d8)
Address 0x7fff3594a8d4 is located at offset 36 in frame <main> of T0's stack:
  This frame has 2 object(s):
    [32, 36) 'test'
    [96, 104) 'one'


See how test ends at 36 but we are accessing location 36.


  parent reply	other threads:[~2014-02-14 19:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-14 17:46 [Bug c++/60201] New: " andrew.stern at itg dot com
2014-02-14 19:20 ` [Bug c++/60201] " pinskia at gcc dot gnu.org
2014-02-14 19:30 ` andrew.stern at itg dot com
2014-02-14 19:44 ` pinskia at gcc dot gnu.org [this message]
2014-02-14 20:00 ` andrew.stern at itg dot com
2014-02-14 20:07 ` andrew.stern at itg dot com
2014-02-14 20:08 ` andrew.stern at itg 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-60201-4-MdvLKfU4lw@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).