GCC Code Coverage Report


Directory: ./
File: lib/mymemory/my_malloc_strndup.c
Date: 2024-06-05 00:36:48
Exec Total Coverage
Lines: 9 10 90.0%
Functions: 1 1 100.0%
Branches: 4 6 66.7%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2023
3 ** my_malloc_strndup
4 ** File description:
5 ** Returns a duplication of a string (src) with a defined size (n)
6 ** with my_malloc
7 */
8 /**
9 * @file my_malloc_strndup.c
10 * @brief The file containing the my_malloc_strndup function
11 * @author Nicolas TORO
12 */
13
14 #include "mymemory.h"
15
16 35 char *my_malloc_strndup(char const *src, int n)
17 {
18 35 char *dest = my_malloc(sizeof(char) * (n + 1), 1);
19 35 int i = 0;
20
21
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if (src == NULL)
22 return NULL;
23
3/4
✓ Branch 0 taken 225 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 190 times.
✓ Branch 3 taken 35 times.
225 while (src[i] != '\0' && i < n) {
24 190 dest[i] = src[i];
25 190 i++;
26 }
27 35 dest[i] = '\0';
28 35 return dest;
29 }
30