-
Access Violation Error
Hi,
Can anyone keep me some reasons why i might be getting an Access Violation error on the following line <code>
int WWText::append(const char s[]) {
char* rawtempstring;
char* tempstring;
int len, i, templen;
try {
/*Error on next line */
rawtempstring = new char [strlen(s) + 1];
/*Program Crashes*/
strcpy(rawtempstring, s);
}
catch (std::bad_alloc) {
printf("Out of Memory!\n");
rawtempstring=0;
return 0;
}
len=cleanText(rawtempstring); </code>
Thanks
-
The only thing I can guess is that the string you're passing in is not null terminated? Other than that I don't see anything indicative of your problem.
(FYI, code tags require square brackets [code][/code] and not angled brackets.)
-
yes, the string being passed (const char s[]) into the function is always null-terminated.
-
My compiler throws some sort of exception when I run out of memory -- like when I forget to deallocate something in a function that's called many times, and finally at some point I'll call new and there won't be enough memory left. Maybe you're doing something like that? I don't know if that would cause an Access Violation though.... just a thought.
-
Not that this helps any but it sounds like your program is attempting to access memory via a descriptor that does not have access rights to it.
Perhaps this error is a side effect of some other error in your code - most likely related to memory management. Often times memory problems won't show up in the piece of code causing the problem, but will cause weird problems later that are very hard to diagnose.
Essentially what everyone else has said thus far.
-
Hint: check the call stack to catch the core problem.
This method proved to be very effective in detecting the root cause of access violations.
-
Code tags use square brackets, [ ], not < >.