Thread: My codes working correctly, nevertheless I get debug error

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    19

    Exclamation My codes working correctly, nevertheless I get debug error

    My codes are working correctly and gives the expected result, but nevertheless I receive DEBUG ERROR!

    ;
    Run time check failure #2 - stack around the variable 'isl' was corrupted (ABORT-RETRY-IGNORE)
    ;

    (Note: "isl" is a Char array, and I'm working on Visual Studio)
    Moreover; When I press ignore there were no problem left, everything is OK. So If everything works fine, why an error?

    Any helps appreciated, thanks in advance.
    Last edited by ilerleartik; 03-17-2012 at 08:56 AM.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,907
    Your codes are not working correctly. It appears to work when not in debug mode, but you just don't see the problem. Debug mode is specifically for finding problems, so it helps catch mistakes like this that are often hard to detect in normal operation. You have stack corruption in both versions, there's probably an array overflow or some pointer bug somewhere. You would have to post your code for us to help you find it.

    The reason that it isn't visible in normal mode is that the stack corruption may not trash anything that is critical to your program running, hence your program doesn't crash, it finishes up "normally". But that doesn't mean everything is okay. Stack corruption means your program is accessing memory in some invalid way. That results in undefined behavior, which is...undefined. Anything, or nothing at all, is valid.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    19
    As soon as Ive read your post and seen "memory","array","overflow" words in it. So I ve checked my array. Yes, I've seen the problem. Because my char array has 50 elements. But I put my char in a for-loop (i(1)60) ...so that's why I got this error, it seems to be fixed for now. Thanks.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,907
    What?!?! How could you possibly make such a mistake?!?! Seriously, how could you? You are #define'ing constants right? You aren't using magic numbers, are you?

    Really, it's quite difficult to make such a mistake if you do something like the following. For every array you ever declare for the rest of your bloody life.
    Code:
    #define MAX_ARRAY_SIZE    50
    
    char my_array[MAX_ARRAY_SIZE];
    
    for (i = 0; i < MAX_ARRAY_SIZE; i++)
        my_array[i]...  // i can never be out of bounds

  5. #5
    Registered User
    Join Date
    Mar 2012
    Posts
    19
    Haha no I couldn't think to #define them just as you ve done. Good idea,though

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loop not working Correctly
    By patneel in forum C Programming
    Replies: 4
    Last Post: 03-15-2012, 07:25 AM
  2. fgets not working correctly
    By Charles Seat in forum C Programming
    Replies: 3
    Last Post: 01-24-2012, 12:17 PM
  3. Max/min function not working correctly
    By En-Motion in forum C++ Programming
    Replies: 6
    Last Post: 03-19-2009, 12:28 AM
  4. function not working correctly
    By mackieinva in forum C Programming
    Replies: 0
    Last Post: 09-29-2007, 08:22 PM
  5. Help me debug following codes
    By asmileguo in forum C++ Programming
    Replies: 12
    Last Post: 09-09-2006, 01:39 AM