-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrlcat.c
45 lines (42 loc) · 1.77 KB
/
strlcat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//arg[2]==NULL -> segv!!!
//arg[2]!=NULL && arg[1]==NULL && arg[3] >0 ->segv!
//arg[2]!=NULL && arg[1]==NULL && arg[3]==0
//->return: strlen(arg2) & dst = (null)!!!
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// #include <limits.h>
int main()
{
char *dst1 = calloc(100, sizeof(char));
char *dst2 = calloc(100, sizeof(char));
printf("1. %zu %s\n", strlcat(dst1, "", 100), dst1);
printf("2. %zu %s\n", strlcat(dst1, "hello ", 100), dst1);
printf("3. %zu %s\n", strlcat(dst1, "world", 100), dst1);
printf("4. %zu %s\n", strlcat(dst1, "world", SIZE_MAX), dst1);
//16 hello worldworld
printf("5. %zu %s\n", strlcat(dst1, "world", SIZE_MAX+1), dst1);
//5 hello worldworld
printf("6. %zu %s\n", strlcat(dst1, "world", SIZE_MAX-1), dst1);
//21 hello worldworldworld
free(dst1);
free(dst2);
dst1 = NULL;
// printf("4. %lu %s\n", strlcat(dst1, NULL, 0), dst1);//segv
// printf("4. %lu %s\n", strlcat(dst1, NULL, 2), dst1);//segv
// printf("4. %lu %s\n", strlcat(dst1, NULL, 100000), dst1);//segv
// printf("5. %lu %s\n", strlcat(dst1, "", 2), dst1);//segv
printf("6. %lu %s\n", strlcat(dst1, "", 0), dst1);//0 (null)
printf("7. %lu %s\n", strlcat(dst1, "is", 0), dst1);//2 (null)
dst1 = "";
printf("8. %lu %s\n", strlcat(dst1, "", 0), dst1);//0
// printf(" 9. %lu %s\n", strlcat(dst1, NULL, 0), dst1);//segv
// printf(" 9. %lu %s\n", strlcat(dst1, NULL, 5), dst1);//segv
dst1 = "hello world";
// printf(" 9. %lu %s\n", strlcat(dst1, NULL, 0), dst1);//segv
// printf(" 9. %lu %s\n", strlcat(dst1, NULL, 10), dst1);//segv
printf(" 9. %lu %s\n", strlcat(dst1, "", 0), dst1);//0 hello world
printf(" 10. %lu %s\n", strlcat(dst1, "abc", 0), dst1);//3 hello world
printf(" 11. %lu %s\n", strlcat(dst1, "!!!hello world!!!", 0), dst1);//17 hello world
return (0);
}