Run-Time Check Failure #2 - Stack around the variable 'foo' was corrupted

arsis-dev

I'm studying for an exam and this is on my practice test. The question is "Which type of error does the following code fragment cause?"

I was pretty sure there would be no errors, but I also can't get it to compile in VS13, I get the error:

Run-Time Check Failure #2 - Stack around the variable 'foo' was corrupted.

    const int MAX = 500;
    int main(void)
    {
        int foo[MAX];
        for (int i = 0; i <= MAX; i++)
        {
            foo[i] = i * 2;
            cout << foo[i] << endl;
        }

    cout << "Press any key to exit." << endl;
    cin.ignore(2);

    return 0;
    }
Mike Seymour

Valid indexes for foo are from 0 to MAX-1 inclusive. MAX is past the end of the array.

Your loop runs up to, and including, MAX. This writes beyond the end of the array, corrupting the stack.

Either increase the array size to MAX+1 so that MAX is in range; or change the loop condition to i < MAX to stop before reaching MAX.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Run-Time Check Failure #2 - Stack around the variable '' was corrupted

From Dev

Run-Time Check Failure #2 - Stack around the variable '...' was corrupted

From Dev

Why am I getting Run-Time Check Failure #2 - Stack around the variable 'x' was corrupted?

From Java

Run-Time Check Failure #2 - Stack around the variable 'sortObject' was corrupted. how to fix?

From Dev

C++ - Run-Time Check Failure #2 - Stack around variable 'sourceCount' was corrupted

From Dev

Run-Time Check Failure #2 - Stack around the variable 'd' was corrupted

From Dev

Basic C++ error. Run-Time Check Failure #2 - Stack around the variable 'matrix' was corrupted

From Dev

C++ - Run-Time Check Failure #2 - Stack around variable 'sourceCount' was corrupted

From Dev

Why am I getting Run-Time Check Failure #2 - Stack around the variable 'x' was corrupted?

From Dev

Run-Time Check Failure #2 - Stack around the variable 'char' was corrupted

From Dev

Run-time Check Failure #2 - Stack around the variable "primes" was corrupted

From Dev

Run-Time Check Failure #2 - Stack around the variable 'result' was corrupted

From Dev

Run-Time Check Failure #2 - Stack around the variable 'obj' was corrupted

From Dev

Run-Time Check Failure #2 - Stack around the variable 'numberchoices' was corrupted

From Dev

RunTime Check Failure #2 - Stack around the variable "tab" was corrupted

From Dev

Stack around the variable was corrupted

From Dev

Stack around variable was corrupted

From Dev

Stack around variable was corrupted

From Dev

stack around the variable...was corrupted

From Dev

"Stack around the variable was corrupted" error

From Dev

Stack around variable 'x' was corrupted

From Dev

Stack around the variable 'sortArray' was corrupted

From Dev

"Stack around the variable was corrupted" error

From Dev

Stack around variable was corrupted - C

From Dev

C - Stack around the variable 'name' was corrupted

From Dev

C: Error with stack around the variable 's' was corrupted

From Dev

Getting error: Stack around the variable was corrupted

From Dev

Stack around the variable was corrupted with pointer arithmetics

From Dev

Array issues: Stack around the variable 'arr' was corrupted

Related Related

  1. 1

    Run-Time Check Failure #2 - Stack around the variable '' was corrupted

  2. 2

    Run-Time Check Failure #2 - Stack around the variable '...' was corrupted

  3. 3

    Why am I getting Run-Time Check Failure #2 - Stack around the variable 'x' was corrupted?

  4. 4

    Run-Time Check Failure #2 - Stack around the variable 'sortObject' was corrupted. how to fix?

  5. 5

    C++ - Run-Time Check Failure #2 - Stack around variable 'sourceCount' was corrupted

  6. 6

    Run-Time Check Failure #2 - Stack around the variable 'd' was corrupted

  7. 7

    Basic C++ error. Run-Time Check Failure #2 - Stack around the variable 'matrix' was corrupted

  8. 8

    C++ - Run-Time Check Failure #2 - Stack around variable 'sourceCount' was corrupted

  9. 9

    Why am I getting Run-Time Check Failure #2 - Stack around the variable 'x' was corrupted?

  10. 10

    Run-Time Check Failure #2 - Stack around the variable 'char' was corrupted

  11. 11

    Run-time Check Failure #2 - Stack around the variable "primes" was corrupted

  12. 12

    Run-Time Check Failure #2 - Stack around the variable 'result' was corrupted

  13. 13

    Run-Time Check Failure #2 - Stack around the variable 'obj' was corrupted

  14. 14

    Run-Time Check Failure #2 - Stack around the variable 'numberchoices' was corrupted

  15. 15

    RunTime Check Failure #2 - Stack around the variable "tab" was corrupted

  16. 16

    Stack around the variable was corrupted

  17. 17

    Stack around variable was corrupted

  18. 18

    Stack around variable was corrupted

  19. 19

    stack around the variable...was corrupted

  20. 20

    "Stack around the variable was corrupted" error

  21. 21

    Stack around variable 'x' was corrupted

  22. 22

    Stack around the variable 'sortArray' was corrupted

  23. 23

    "Stack around the variable was corrupted" error

  24. 24

    Stack around variable was corrupted - C

  25. 25

    C - Stack around the variable 'name' was corrupted

  26. 26

    C: Error with stack around the variable 's' was corrupted

  27. 27

    Getting error: Stack around the variable was corrupted

  28. 28

    Stack around the variable was corrupted with pointer arithmetics

  29. 29

    Array issues: Stack around the variable 'arr' was corrupted

HotTag

Archive