pbm avec sanitizer
This commit is contained in:
131
get_next_line.c
131
get_next_line.c
@@ -1,60 +1,56 @@
|
|||||||
/* ************************************************************************** */
|
//-g -fsanitize=address
|
||||||
/* */
|
//https://github.com/charMstr/GNL_lover
|
||||||
/* ::: :::::::: */
|
//https://github.com/mrjvs/42cursus_gnl_tests
|
||||||
/* get_next_line.c :+: :+: :+: */
|
//https://github.com/Sherchryst/gnlkiller
|
||||||
/* +:+ +:+ +:+ */
|
//https://github.com/Hellio404/Get_Next_Line_Tester
|
||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
//https://github.com/TinfoilPancakes/get-next-line-testing-tools
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2019/12/11 00:27:09 by hulamy #+# #+# */
|
|
||||||
/* Updated: 2019/12/16 14:21:00 by hulamy ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "get_next_line.h"
|
#include "get_next_line.h"
|
||||||
|
|
||||||
/*
|
|
||||||
** #include <stdio.h> //for printf
|
#include <stdio.h> //for printf
|
||||||
** #include <fcntl.h> //for open
|
#include <fcntl.h> //for open
|
||||||
**
|
|
||||||
** int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
** {
|
{
|
||||||
** int *fd;
|
int *fd;
|
||||||
** int i;
|
int i;
|
||||||
** int j;
|
int j;
|
||||||
** char *line;
|
int ret;
|
||||||
**
|
char *line;
|
||||||
** if (ac < 2)
|
|
||||||
** return (0);
|
if (ac < 2)
|
||||||
** line = NULL;
|
return (0);
|
||||||
** i = 0;
|
line = NULL;
|
||||||
** if (!(fd = (int *)malloc(sizeof(int) * ac)))
|
i = 0;
|
||||||
** return (0);
|
if (!(fd = (int *)malloc(sizeof(int) * ac)))
|
||||||
** while (++i <= ac - 1)
|
return (0);
|
||||||
** fd[i - 1] = open(av[i], O_RDONLY);
|
while (++i <= ac - 1)
|
||||||
** i = 0;
|
fd[i - 1] = open(av[i], O_RDONLY);
|
||||||
** j = 0;
|
i = 0;
|
||||||
** while (j < ac - 1)
|
j = 0;
|
||||||
** {
|
while (j < ac - 1)
|
||||||
** if (get_next_line(fd[i], &line) > 0)
|
{
|
||||||
** {
|
if ((ret = get_next_line(fd[i], &line)) > 0)
|
||||||
** printf("fd%i| %s\n", fd[i], line);
|
{
|
||||||
** free(line);
|
printf("[fd%i-%i] %s\n", fd[i], ret, line);
|
||||||
** j = 0;
|
free(line);
|
||||||
** }
|
j = 0;
|
||||||
** else
|
}
|
||||||
** {
|
else
|
||||||
** printf("fd%i|*FINI*\n", fd[i]);
|
{
|
||||||
** j++;
|
printf("[fd%i-%i]*FINI*\n", fd[i], ret);
|
||||||
** }
|
j++;
|
||||||
** i++;
|
}
|
||||||
** if (i >= ac - 1)
|
i++;
|
||||||
** i = 0;
|
if (i >= ac - 1)
|
||||||
** }
|
i = 0;
|
||||||
** free (fd);
|
}
|
||||||
** // while (1);
|
free (fd);
|
||||||
** return (0);
|
while (1);
|
||||||
** }
|
return (0);
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
|
||||||
int multi_fd(int fd, t_gnlist **lst)
|
int multi_fd(int fd, t_gnlist **lst)
|
||||||
{
|
{
|
||||||
@@ -114,16 +110,23 @@ int hasnewline(char *str, t_gnlist *lst, char **line)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_lst(t_gnlist **lst, const int fd)
|
//void free_lst(t_gnlist **lst, const int fd)
|
||||||
|
void free_lst(t_gnlist **lst)
|
||||||
{
|
{
|
||||||
t_gnlist *tmp;
|
t_gnlist *tmp;
|
||||||
|
|
||||||
tmp = *lst;
|
tmp = (*lst)->next->next;
|
||||||
while ((*lst)->next && (*lst)->next->lfd != fd)
|
(*lst)->lfd = (*lst)->next->lfd;
|
||||||
(*lst) = (*lst)->next;
|
free((*lst)->string);
|
||||||
free(tmp->string);
|
(*lst)->string = (*lst)->next->string;
|
||||||
free(tmp);
|
free((*lst)->next);
|
||||||
(*lst)->next = (*lst)->next->next;
|
(*lst)->next = tmp;
|
||||||
|
// tmp = *lst;
|
||||||
|
// while ((*lst)->next && (*lst)->next->lfd != fd)
|
||||||
|
// (*lst) = (*lst)->next;
|
||||||
|
// free(tmp->string);
|
||||||
|
// free(tmp);
|
||||||
|
// (*lst)->next = (*lst)->next->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_next_line(const int fd, char **line)
|
int get_next_line(const int fd, char **line)
|
||||||
@@ -133,7 +136,8 @@ int get_next_line(const int fd, char **line)
|
|||||||
static t_gnlist *lst = NULL;
|
static t_gnlist *lst = NULL;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
if (!(multi_fd(fd, &lst)) || !(ret = 1) || !line || fd < 0)
|
ret = 1;
|
||||||
|
if (!(multi_fd(fd, &lst)) || !line || fd < 0 || BUFFER_SIZE < 1)
|
||||||
return (-1);
|
return (-1);
|
||||||
while (ret > 0)
|
while (ret > 0)
|
||||||
{
|
{
|
||||||
@@ -149,6 +153,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);
|
//free_lst(&lst, fd);
|
||||||
|
//free_lst(&lst);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/01/29 10:19:37 by hulamy #+# #+# */
|
/* Created: 2019/01/29 10:19:37 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/12/16 14:07:14 by hulamy ### ########.fr */
|
/* Updated: 2019/12/19 19:38:39 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -28,7 +28,8 @@ int get_next_line(const int fd, char **line);
|
|||||||
int multi_fd(int fd, t_gnlist **lst);
|
int multi_fd(int fd, t_gnlist **lst);
|
||||||
char *ft_strjoinfree(char const *s1, char const *s2);
|
char *ft_strjoinfree(char const *s1, char const *s2);
|
||||||
int hasnewline(char *str, t_gnlist *lst, char **line);
|
int hasnewline(char *str, t_gnlist *lst, char **line);
|
||||||
void free_lst(t_gnlist **lst, const int fd);
|
//void free_lst(t_gnlist **lst, const int fd);
|
||||||
|
void free_lst(t_gnlist **lst);
|
||||||
|
|
||||||
size_t ft_strlen(const char *str);
|
size_t ft_strlen(const char *str);
|
||||||
void *ft_memmove(void *dst, const void *src, size_t len);
|
void *ft_memmove(void *dst, const void *src, size_t len);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/12/16 14:07:51 by hulamy #+# #+# */
|
/* Created: 2019/12/16 14:07:51 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/12/16 14:11:18 by hulamy ### ########.fr */
|
/* Updated: 2019/12/19 19:38:21 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user