通过VS地址擦除系统定位缓冲区溢出问题
1 #define _CRT_SECURE_NO_WARNINGS 2 #include <iostream> 3 using namespace std; 4 5 char sBuf[5]; 6 int main() 7 { 8 int nNum = 1; 9 strcpy(sBuf, "Hello World!"); 10 11 for (int i = 1; i < 101; i++) 12 nNum += i; 13 14 cout << "Num = " << nNum << endl; 15 getchar(); 16 }
1 #define _CRT_SECURE_NO_WARNINGS 2 #include <iostream> 3 using namespace std; 4 5 int main() 6 { 7 int nNum = 0; 8 char sBuf[5]; 9 strcpy(sBuf, "Hello World!"); 10 11 for (int i = 1; i < 101; i++) 12 nNum += i; 13 14 cout << "Num = " << nNum << endl; 15 getchar(); 16 }
在实际工程中,如果遇到这种问题,定位是相当复杂的。
堆缓冲区和上面两种差不多,就不放代码了。