Gaaah! Index out of bounds?! Why?

Started by
3 comments, last by InvalidPointer 15 years, 8 months ago
I'm working on a quick-and-dirty debug console for my pet engine/software engineering testbed and for some rather peculiar reason std::string::at() keeps throwing out-of-bounds excpetions in this little code segment. Would anyone have any tips or help in determining where the problem is? I suspect it's in the delimiting conditional, but some debug work by me yielded that temp always shows up as a whitespace even when the character it *should* be isn't. I can confirm that the passed-in command string is valid.

GMForceInline SupernaturalString ParseCommandLine(SupernaturalString cmdString) // tokenizes a string and executes the associated commands
	{
		// TODO: Do some search optimization, maybe figure out a means of generating a 'position' value for the std::map ops
		SupernaturalString cmd;
		bool keepGoing = true;
		CVarDBIter iter;
		size_t i = 0;
		do
		{
			char temp = cmd.at(i);
			if((temp != '\n') && (temp != ' '))
			{
				std::cout << temp << std::endl;
				cmd.push_back(temp);
				std::cout << cmd;
				++i;
			}
			else
			{
				keepGoing = false;
				break;
			}
		} while(keepGoing);
		iter = mappedVars.find(cmd);
		if(iter != mappedVars.end())
		{
			return mappedVars[cmd].AsString();
		}
		return string("Unknown variable " + cmdString);
	}
And on a side note, if anyone has any useful articles or design advice for debug consoles as a whole I'd love to get my hands on 'em :)
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
Advertisement
Well the obvious reason would be if the string doesn't contain a '\n' or a ' '.
Quote:Original post by SiCrane
Well the obvious reason would be if the string doesn't contain a '\n' or a ' '.

Quote:I can confirm that the passed-in command string is valid.


I did think of that one, but I also would agree that the problem is probably something really stupidly simple XD
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
What is a "SupernaturalString" and why are you checking a locally created string rather than the parameter string? which is empty and causing the error.
Quote:Original post by CmpDev
What is a "SupernaturalString" and why are you checking a locally created string rather than the parameter string? which is empty and causing the error.


I knew it was stupid. Thanks!

(That's my string wrapper and extension class, created mostly for portability)
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

This topic is closed to new replies.

Advertisement