如果不使用复制字符串,程序可以正常工作strcpy
,但我想知道原因是什么?
#include <stdio.h>
#include <string.h>
int main ()
{
int mat;
char test1[20]={"Hex"} ;
char test2[20]={"agonal"} ;
strcpy(test1,"Diagonal"); // the print outputs the concatenated test if strcpy is commented out
//printf("a=%c\nb=%c\n",test1[0],test1[1]);
printf("Concatenated test=%s", strcat(test1, test2));
return 0;
}
ERROR MESSAGE
*** buffer overflow detected ***: ./prog terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x48)[0xb75b6ae8]
/lib/libc.so.6[0xb75b4b30]
/lib/libc.so.6[0xb75b3dcd]
./prog(__gxx_personality_v0+0x14d)[0x804858d]
./prog(__gxx_personality_v0+0x31)[0x8048471]
======= Memory map: ========