Sign in to follow this  
nimnimnim

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

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"
  002
  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
Quote:
(*(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:
const_iterator::operator=(it);

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++:
http://nim.pansarvagn.net/nim_sequence_080514_2.zip

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.
http://nim.pansarvagn.net/nim_sequence_080514_3.zip

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this