GCC Code Coverage Report


Directory: ./
File: lib/mymemory/my_malloc_strndup.c
Date: 2024-05-07 14:54:03
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 14 char *my_malloc_strndup(char const *src, int n)
17 {
18 14 char *dest = my_malloc(sizeof(char) * (n + 1), 1);
19 14 int i = 0;
20
21
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (src == NULL)
22 return NULL;
23
3/4
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
✓ Branch 3 taken 14 times.
84 while (src[i] != '\0' && i < n) {
24 70 dest[i] = src[i];
25 70 i++;
26 }
27 14 dest[i] = '\0';
28 14 return dest;
29 }
30