Run-Time Check Failure #2

Run-Time Check Failure #2 

 

This bug occurred during symmetric matrix compression. After checking, it was found that the array subscript had overflow.

For example: Compress symmetric matrix (matrix index 1 starts, array index 0 starts)

In the for loop input array (int i=0;i<n+1;i++) but the inner loop (int j=0;i<m;j++) corresponds to different subscripts, so the main loop variable control is required , and the output When using (int i=0;i<n;i++), the subscript does not match and overflow occurs. When the program is running, a breakpoint error will occur, and the contents of the array corresponding to the overflowed subscript will appear garbled!

 

Run-Time Check Failure #2:

analysis:

     1, This error is generally caused by out-of-bounds access in the space allocated for variables (mostly arrays are out of bounds).

Possible situations:

  1.  Strcpy, memcpy, strncpy, stpcpy, bcopy and other copy areas do not match in size, causing conflicts or overflow
  2. When using memset/ZeroMemory to initialize a data structure or an array, it is caused by the wrong size setting ( mostly this problem )
  3. Maybe the pointer is moving, pointing to the wrong
  4. It is also possible that the variable is assigned, but the variable is not found

Guess you like

Origin blog.csdn.net/qq_46861651/article/details/113306942