0

I seem to be able to write as many characters as I want into "buffer" even though I declare it as length 1 - why is this?

string teststring = "teststring";
	cout << teststring << endl;

	char buffer[1];
	itoa(34567,buffer,10);

	teststring.append(buffer);
	cout << teststring << endl;

Thanks!

Dave

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Narue
0

>why is this?
Dumb luck. You happened to write to memory that isn't critical to the operation of the program. Therefore, it doesn't crash immediately, only silently corrupts whatever was there. Whether it seems to work or not, you're always taking a huge risk by overflowing your memory.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.