Access Violation

This line:
string domainName = argv[1]; cause "Access Violation" in debug. But no problems when running without debug.

Can someone pls explain what's going on?


Either argv[1] is not null-terminated, which allows the std::string constructor to read past the end, or the heap has been corrupted somewhere else, which causes the memory allocation to fail.
Ok, if it's not null terminated by default, then that's the problem. And if it's not I guess I cant just add a 0 to it because the argv is not greater than its content?
Last edited on
I just threw in the first option for the sake of completeness, really. My money is on the second one.
argv is the command line arg. And the line in my example is the only line of code in my program. So I dont understand the Access Violation :s
Post the entire program.

Oh, wait. I know. If you don't pass any arguments to the program and don't check argc, you're reading outsize the bounds of argv. argv[1] is not a valid pointer.
Last edited on
Post the entire program.



int __cdecl main(int argc, char **argv)
{
string domainName = argv[1]; //argv[1] / value passed in = example
}
See my addendum above.
I have passed in a value
Even when running through the debugger? Are you sure?
Haha, nice catch. Thanks man :)
Topic archived. No new replies allowed.