no more leaks but printf too long

This commit is contained in:
hugodu69
2020-02-27 00:00:11 +01:00
parent 319204ecc5
commit c82a18587a
5 changed files with 21 additions and 13 deletions

BIN
ft_printf

Binary file not shown.

View File

@@ -91,7 +91,11 @@ int ft_printf(char *string, ...)
if (!(print = ft_flag_transform(s, print, type))) if (!(print = ft_flag_transform(s, print, type)))
return (-1); return (-1);
length += ft_put_word(print); length += ft_put_word(print);
free(print);
} }
free(s);
free(type);
} }
free(s);
return (length); return (length);
} }

4
main.c
View File

@@ -68,9 +68,13 @@ char *ft_compare(int fd1, int fd2, int *error)
ret2 = get_next_line(fd2, &line); ret2 = get_next_line(fd2, &line);
if (ft_strcmp(tmp, line) != 0) if (ft_strcmp(tmp, line) != 0)
{ {
free(line);
free(tmp);
(*error)++; (*error)++;
return ("\033[91mHO HO..\033[0m"); return ("\033[91mHO HO..\033[0m");
} }
free(line);
free(tmp);
} }
if (ret1 != ret2) if (ret1 != ret2)
{ {

View File

@@ -74,27 +74,27 @@ int ft_put_word(char *s)
int ft_expand_star(int nbr, char **string) int ft_expand_star(int nbr, char **string)
{ {
char *s; char *s;
char *strnbr; char *n;
int i; int i;
int j; int j;
int k;
strnbr = ft_itoa(nbr); n = ft_itoa(nbr);
i = ft_strlen(strnbr) + ft_strlen(*string) - 1; if (!(s = ft_memalloc(sizeof(char) * (ft_strlen(n) + ft_strlen(*string)))))
if (!(s = (char *)malloc(sizeof(char) * (i + 1))))
return (0); return (0);
s[i] = '\0'; i = -1;
i = 0;
j = 0; j = 0;
while ((*string)[i] != '\0') k = 0;
while ((*string)[++i] != '\0')
{ {
s[j] = (*string)[i]; s[j] = (*string)[i];
if (s[j] == '*') if (s[j] == '*')
while (*strnbr != '\0') while (n[k] != '\0')
s[j++] = *(strnbr++); s[j++] = n[k++];
else else
j++; j++;
i++;
} }
free(n);
free(*string); free(*string);
*string = s; *string = s;
return (1); return (1);

View File

@@ -46,15 +46,15 @@ char *conv_u(char c, unsigned long int i)
{ {
char *s; char *s;
s = ft_utoa(i);
if (c == 's') if (c == 's')
return (strdup((char *)i)); return (strdup((char *)i));
s = ft_utoa(i);
if (c == 'u') if (c == 'u')
return (s); return (s);
if (c == 'x' || c == 'p') if (c == 'x' || c == 'p')
return (ft_convertbase(s, "0123456789", "0123456789abcdef")); return (ft_convertbase_free(s, "0123456789", "0123456789abcdef"));
if (c == 'X') if (c == 'X')
return (ft_convertbase(s, "0123456789", "0123456789ABCDEF")); return (ft_convertbase_free(s, "0123456789", "0123456789ABCDEF"));
return (NULL); return (NULL);
} }