1919extern char * _custom_fossil_test_strdup (const char * str );
2020
2121void fossil_mock_init (MockCallList * list ) {
22+ if (!list ) {
23+ return ;
24+ }
2225 list -> head = NULL ;
2326 list -> tail = NULL ;
2427 list -> size = 0 ;
@@ -40,15 +43,47 @@ void fossil_mock_destroy(MockCallList *list) {
4043 free (current );
4144 current = next ;
4245 }
46+ list -> head = NULL ;
47+ list -> tail = NULL ;
48+ list -> size = 0 ;
4349}
4450
4551void fossil_mock_add_call (MockCallList * list , const char * function_name , char * * arguments , int num_args ) {
52+ if (!list || !function_name || !arguments ) {
53+ return ;
54+ }
55+
4656 MockCall * call = (MockCall * )malloc (sizeof (MockCall ));
57+ if (!call ) {
58+ return ;
59+ }
60+
4761 call -> function_name = _custom_fossil_test_strdup (function_name );
62+ if (!call -> function_name ) {
63+ free (call );
64+ return ;
65+ }
66+
4867 call -> arguments = (char * * )malloc (num_args * sizeof (char * ));
68+ if (!call -> arguments ) {
69+ free (call -> function_name );
70+ free (call );
71+ return ;
72+ }
73+
4974 for (int i = 0 ; i < num_args ; ++ i ) {
5075 call -> arguments [i ] = _custom_fossil_test_strdup (arguments [i ]);
76+ if (!call -> arguments [i ]) {
77+ for (int j = 0 ; j < i ; ++ j ) {
78+ free (call -> arguments [j ]);
79+ }
80+ free (call -> arguments );
81+ free (call -> function_name );
82+ free (call );
83+ return ;
84+ }
5185 }
86+
5287 call -> num_args = num_args ;
5388 call -> next = NULL ;
5489
@@ -62,6 +97,10 @@ void fossil_mock_add_call(MockCallList *list, const char *function_name, char **
6297}
6398
6499void fossil_mock_print (MockCallList * list ) {
100+ if (!list ) {
101+ return ;
102+ }
103+
65104 MockCall * current = list -> head ;
66105 while (current ) {
67106 printf ("Function: %s\n" , current -> function_name );
0 commit comments