Jump to content
  • Advertisement
Sign in to follow this  

corruption of member occuring between end of method scope and return to calling scope

This topic is 3688 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

reproducing minimal console app set up with class header: OLD--http://nim.pansarvagn.net/nim_sequence_080514.zip-- EDIT: see following post for later version
  001	#include "nim/sequence.h"
  003	void main(int argc, char argv[])
  004	{
  005		nim::sequence<char> seq;
  006		seq.push_back('a');
  007		nim::sequence<char>::const_iterator_looping it;
  008		it = seq.before(); //happens somewhere in here?
O 009		; //observe corruption orz
  010	};
and set a break point at line 263 in sequence.h like so:
  258	const_iterator_looping& operator =( const iterator& it )
  259	{
  260		(*(const_iterator*)this) = (*(const_iterator*)&it);
  261		_begin = it._current;
  262		return *this;
O 263	}
the corruption has not taken place at a break-point at the } of the final operator= scope but mysteriously it's there if you look at a breakpoint directly outside of the call in the calling scope :< much obliged, if the problem doesn't sound familiar and you can't say anything without testing it, and bother to :) greatest TIA :U [Edited by - nimnimnim on May 14, 2008 7:11:55 PM]

Share this post

Link to post
Share on other sites
(*(const_iterator*)this) = (*(const_iterator*)&it);

Do const_iterator_looping and iterator both inherit from const_iterator? If so, this type safe alternative should be equivalent and type safe:

If not, well, it's no wonder this reinterpret_cast<>ing doesn't work.

Share this post

Link to post
Share on other sites
thanks! yes ofcourse the casts are really nasty :( but they're all valid anyways..
but good thing you pointed it out or I would've left it like that!
I've changed all the ugly casts to proper c++:

problem still remains. :(

EDIT: oh sorry, I forgot: it's the member _item_type* _begin of const_iterator_looping which turns feeefeee...

anyway I realised this member was a drunken design and there's no need for it so I removed it :/ some way to shout fire.. well it still is alarming I've no clue why it happens..

here's the current version anyway... none of the fixes to other stuff fixed this issue.. I doubt it has anything with buffer overrun to do.. if you add in _begin again it'll behave like before.

thanks for looking anyway, sorry for such a useless thread :)

[Edited by - nimnimnim on May 14, 2008 11:10:51 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!