#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    13
    Rep Power
    0

    Error disappears in debug mode


    I have some evil error in my code, index out of bound probably. It overwrites some stuff in the programs code.
    However in debug mode(im using NetBeans) it runs perfectly. Probably in debug mode it does some different memory allocation, I dont know.
    Why is this? Whats the running/memory difference between normal run and debug mode?
    Thanks a lot!
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,365
    Rep Power
    1870
    > Why is this? Whats the running/memory difference between normal run and debug mode?
    Consider something like this
    char buff[10];
    int i;

    In debug mode, the compiler may allow more "dead space" at the end of the array to permit easier detection of buffer overruns. So it may allow 16 bytes for the array before storing the int.

    In release mode, all it cares about is efficient allocation. In this case, the compiler would just round up to the next sizeof(int) boundary - say 12, and store the int.

    Now, if in your code you have a buffer overrun up to say 14 chars, it will just fill the dead space in debug mode, and completely trash your int in release mode.

    Netbeans seems to be just an IDE.
    What is the operating system and compiler you're using?

    Comments on this post

    • ptr2void agrees
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    13
    Rep Power
    0
    Originally Posted by salem
    > Why is this? Whats the running/memory difference between normal run and debug mode?
    Consider something like this
    char buff[10];
    int i;

    In debug mode, the compiler may allow more "dead space" at the end of the array to permit easier detection of buffer overruns. So it may allow 16 bytes for the array before storing the int.

    In release mode, all it cares about is efficient allocation. In this case, the compiler would just round up to the next sizeof(int) boundary - say 12, and store the int.

    Now, if in your code you have a buffer overrun up to say 14 chars, it will just fill the dead space in debug mode, and completely trash your int in release mode.

    Netbeans seems to be just an IDE.
    What is the operating system and compiler you're using?
    Thanks!
    WinXP, g++
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    13
    Rep Power
    0
    Sorry for the bump!
    The problem is solved, maybe somebody will have the same thing once:

    I forget to set a class member to null, so it was always the same crap in it from the previous function. The "error" disappeared in debug mode, and when I changed the prev function it made a slightly different error so I thought its the previous func:)
    It was an evil error.

    Comments on this post

    • salem agrees : Nice feedback

IMN logo majestic logo threadwatch logo seochat tools logo