correction deux erreurs free avant return 0 et free list avant utilisation
This commit is contained in:
116
get_next_line.c
116
get_next_line.c
@@ -1,56 +1,69 @@
|
|||||||
//-g -fsanitize=address
|
/* ************************************************************************** */
|
||||||
//https://github.com/charMstr/GNL_lover
|
/* */
|
||||||
//https://github.com/mrjvs/42cursus_gnl_tests
|
/* ::: :::::::: */
|
||||||
//https://github.com/Sherchryst/gnlkiller
|
/* get_next_line.c :+: :+: :+: */
|
||||||
//https://github.com/Hellio404/Get_Next_Line_Tester
|
/* +:+ +:+ +:+ */
|
||||||
//https://github.com/TinfoilPancakes/get-next-line-testing-tools
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/12/21 00:28:33 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/12/21 00:28:39 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "get_next_line.h"
|
#include "get_next_line.h"
|
||||||
|
|
||||||
|
/*
|
||||||
#include <stdio.h> //for printf
|
** //-g -fsanitize=address
|
||||||
#include <fcntl.h> //for open
|
** //:set noendofline binary
|
||||||
|
** //https://github.com/charMstr/GNL_lover
|
||||||
int main(int ac, char **av)
|
** //https://github.com/mrjvs/42cursus_gnl_tests
|
||||||
{
|
** //https://github.com/Sherchryst/gnlkiller
|
||||||
int *fd;
|
** //https://github.com/Hellio404/Get_Next_Line_Tester
|
||||||
int i;
|
** //https://github.com/TinfoilPancakes/get-next-line-testing-tools
|
||||||
int j;
|
**
|
||||||
int ret;
|
** #include <stdio.h> //for printf
|
||||||
char *line;
|
** #include <fcntl.h> //for open
|
||||||
|
**
|
||||||
if (ac < 2)
|
** int main(int ac, char **av)
|
||||||
return (0);
|
** {
|
||||||
line = NULL;
|
** int *fd;
|
||||||
i = 0;
|
** int i;
|
||||||
if (!(fd = (int *)malloc(sizeof(int) * ac)))
|
** int j;
|
||||||
return (0);
|
** int ret;
|
||||||
while (++i <= ac - 1)
|
** char *line;
|
||||||
fd[i - 1] = open(av[i], O_RDONLY);
|
**
|
||||||
i = 0;
|
** if (ac < 2)
|
||||||
j = 0;
|
** return (0);
|
||||||
while (j < ac - 1)
|
** line = NULL;
|
||||||
{
|
** i = 0;
|
||||||
if ((ret = get_next_line(fd[i], &line)) > 0)
|
** if (!(fd = (int *)malloc(sizeof(int) * ac)))
|
||||||
{
|
** return (0);
|
||||||
printf("[fd%i-%i] %s\n", fd[i], ret, line);
|
** while (++i <= ac - 1)
|
||||||
free(line);
|
** fd[i - 1] = open(av[i], O_RDONLY);
|
||||||
j = 0;
|
** i = 0;
|
||||||
}
|
** j = 0;
|
||||||
else
|
** while (j < ac - 1)
|
||||||
{
|
** {
|
||||||
printf("[fd%i-%i]*FINI*\n", fd[i], ret);
|
** if ((ret = get_next_line(fd[i], &line)) > 0)
|
||||||
j++;
|
** {
|
||||||
}
|
** printf("[fd%i-%i] %s\n", fd[i], ret, line);
|
||||||
i++;
|
** free(line);
|
||||||
if (i >= ac - 1)
|
** j = 0;
|
||||||
i = 0;
|
** }
|
||||||
}
|
** else
|
||||||
free (fd);
|
** {
|
||||||
//while (1);
|
** printf("[fd%i-%i]*FINI*\n", fd[i], ret);
|
||||||
return (0);
|
** j++;
|
||||||
}
|
** }
|
||||||
|
** i++;
|
||||||
|
** if (i >= ac - 1)
|
||||||
|
** i = 0;
|
||||||
|
** }
|
||||||
|
** free (fd);
|
||||||
|
** //while (1);
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
int multi_fd(int fd, t_gnlist **lst)
|
int multi_fd(int fd, t_gnlist **lst)
|
||||||
{
|
{
|
||||||
@@ -146,6 +159,7 @@ int get_next_line(const int fd, char **line)
|
|||||||
return (-1);
|
return (-1);
|
||||||
if (*(lst->string) && ++ret == 1)
|
if (*(lst->string) && ++ret == 1)
|
||||||
(lst->string)[0] = '\0';
|
(lst->string)[0] = '\0';
|
||||||
free_lst(&lst, fd);
|
else
|
||||||
|
free_lst(&lst, fd);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/12/16 14:08:36 by hulamy #+# #+# */
|
/* Created: 2019/12/16 14:08:36 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/12/16 14:25:08 by hulamy ### ########.fr */
|
/* Updated: 2019/12/21 00:29:07 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -122,8 +122,8 @@ void free_lst(t_gnlist **lst, const int fd)
|
|||||||
while ((*lst)->next && (*lst)->next->lfd != fd)
|
while ((*lst)->next && (*lst)->next->lfd != fd)
|
||||||
(*lst) = (*lst)->next;
|
(*lst) = (*lst)->next;
|
||||||
free(tmp->string);
|
free(tmp->string);
|
||||||
free(tmp);
|
|
||||||
(*lst)->next = (*lst)->next->next;
|
(*lst)->next = (*lst)->next->next;
|
||||||
|
free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_next_line(const int fd, char **line)
|
int get_next_line(const int fd, char **line)
|
||||||
@@ -149,6 +149,7 @@ int get_next_line(const int fd, char **line)
|
|||||||
return (-1);
|
return (-1);
|
||||||
if (*(lst->string) && ++ret == 1)
|
if (*(lst->string) && ++ret == 1)
|
||||||
(lst->string)[0] = '\0';
|
(lst->string)[0] = '\0';
|
||||||
free_lst(&lst, fd);
|
else
|
||||||
|
free_lst(&lst, fd);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user