有人能解释一下为什么我的strcat要这么做吗?
我似乎找不到为什么要在源字符串的一部分上重写。
输出如下所示:新字符串: HelloThis应在str1中str1h 0中的反斜杠0之后
global strcat
extern strlenstrcat:
push ebp
mov ebp, esp
push ecx
push esi
push edi
push ebx
push edx
xor edx, edx
xor edi, edi
xor ebx, ebx
xor esi, esi
xor ecx, ecx
mov edi, [ebp + 8]
mov esi, [ebp + 12]
push edi
call strlen
pop edi
mov ecx, eax
xor eax, eax
push esi
call strlen
pop esi
mov ebx, eax
xor eax, eax
cmp [edi + ecx], byte 0b
je PUT_LINE
jmp FINALIZE_ENDPUT_LINE:
cmp ebx, eax
je END
mov dl, [esi + eax]
mov [edi + ecx], dl
xor edx, edx
inc eax
inc ecx
jmp PUT_LINE结束:
mov eax, [ebp + 8]
jmp FINALIZE_ENDFINALIZE_END:
pop edx
pop ebx
pop edi
pop esi
pop ecx
mov esp, ebp
pop ebp
ret~
~
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
char* str1;
char* str2;
str1 = strdup("Hello");
str2 = strdup("This shall be after my backslash 0 in str1");
printf("New String : %s\n", strcat(str1, str2));
return (0);
}~
发布于 2012-03-10 20:41:13
strcat()将一个字符串中的字符附加到另一个字符串中。修改目标字符串。因此,strcat(str1, str2)修改了str1,使其也包含str2的内容。
由于没有为str1分配足够的内存来容纳这两个字符串中的字符,这会导致溢出。
https://stackoverflow.com/questions/9646414
复制相似问题