aboutsummaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-10-29 05:20:35 +0100
committerCharles <sircharlesaze@gmail.com>2019-10-29 05:20:35 +0100
commit66ed3290deb97057875aa7372741595e3fa290a6 (patch)
treec2123744a3775f274a07bab24841690498e36fad /parse.c
parent87bce91050b56915dcf5964f6f66d5f47299e7f3 (diff)
downloadft_printf-66ed3290deb97057875aa7372741595e3fa290a6.tar.gz
ft_printf-66ed3290deb97057875aa7372741595e3fa290a6.tar.bz2
ft_printf-66ed3290deb97057875aa7372741595e3fa290a6.zip
String conversion refactor, malloc protection
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/parse.c b/parse.c
index 83a7d55..6738566 100644
--- a/parse.c
+++ b/parse.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/29 00:11:33 by cacharle #+# #+# */
-/* Updated: 2019/10/29 00:11:50 by cacharle ### ########.fr */
+/* Updated: 2019/10/29 05:19:00 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -36,6 +36,7 @@ t_flist *parse(char *format)
if ((tmp = list_new(parsed)) == NULL)
return (list_destroy(&format_list));
list_push_front(&format_list, tmp);
+ format += format_list->content->len;
}
return (list_reverse(format_list));
}
@@ -44,14 +45,16 @@ t_pformat *parse_reduced(char *fmt)
{
t_pformat *pformat;
int i;
+ char *start;
i = 0;
while (strrchr_index(CONVERSIONS_STR, fmt[i]) == -1)
i++;
- if ((fmt = ft_strndup(fmt, i + 1)) == NULL)
+ if ((start = ft_strndup(fmt, i + 1)) == NULL)
return (NULL);
if ((pformat = (t_pformat*)malloc(sizeof(t_pformat))) == NULL)
return (NULL);
+ fmt = start;
pformat->precision = -1;
pformat->min_width = -1;
pformat->flags = 0;
@@ -60,6 +63,7 @@ t_pformat *parse_reduced(char *fmt)
fmt[pformat->len - 1] = '\0';
fmt = extract_standalone_flags(pformat, fmt);
fmt = extract_min_width(pformat, fmt);
- fmt = extract_precision(pformat, fmt);
+ extract_precision(pformat, fmt);
+ free(start);
return (pformat);
}