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

View File

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

View File

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