1
0
Fork 0
forked from ahurac/dotfiles

separator : suppression d'un comportement indéfini avec strlen

This commit is contained in:
Hippolyte Chauvin 2023-11-23 10:51:53 +01:00
parent d1f41b37c0
commit c9d485472e

View file

@ -12,6 +12,9 @@ static char *separation_character_line(const char *separation_character, const u
const size_t character_length = strlen(separation_character);
char *line = malloc(line_length * sizeof(char));
// Avoiding undefined behaviour with strlen if no null byte is
// present at the end of line
*line = 0;
while (strlen(line) + character_length <= line_length) {
strncat(line, separation_character, character_length);