Thread: Access Violation Error

  1. #1
    Scott
    Guest

    Exclamation 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

  2. #2
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    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.)

  3. #3
    Scott
    Guest

    Exclamation

    yes, the string being passed (const char s[]) into the function is always null-terminated.

  4. #4
    Registered User codegirl's Avatar
    Join Date
    Jun 2003
    Posts
    76
    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.
    My programs don't have bugs, they just develop random features.

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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.

  6. #6
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    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.

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Code tags use square brackets, [ ], not < >.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  4. file reading
    By gunghomiller in forum C++ Programming
    Replies: 9
    Last Post: 08-07-2007, 10:55 PM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM