aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ft_get_colors.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/ft_get_colors.c b/src/ft_get_colors.c
index c2e8b31..2e09fc6 100644
--- a/src/ft_get_colors.c
+++ b/src/ft_get_colors.c
@@ -3,6 +3,19 @@
#include <stddef.h>
static int
+ft_check_digits(const char *word)
+{
+ size_t i;
+
+ i = 0;
+ while (ft_isdigit(word[i]))
+ i++;
+ if (i != ft_strlen(word))
+ return (-1);
+ return (0);
+}
+
+static int
ft_get_f_color(char *line, char **words, t_win *wlist)
{
char **num;
@@ -11,7 +24,10 @@ ft_get_f_color(char *line, char **words, t_win *wlist)
return (-1);
if (!(num = ft_split(words[1], ',')))
return (-1);
- if (!num[0] || !num[1] || !num[2] || num[3])
+ if (!num[0] || !num[1] || !num[2] || num[3] ||
+ ft_check_digits(num[0]) || ft_check_digits(num[1]) ||
+ ft_check_digits(num[2]) || ft_atoi(num[0]) > 255 ||
+ ft_atoi(num[1]) > 255 || ft_atoi(num[2]) > 255)
{
ft_free_words(num, NULL);
return (-1);
@@ -35,7 +51,10 @@ ft_get_c_color(char *line, char **words, t_win *wlist)
return (-1);
if (!(num = ft_split(words[1], ',')))
return (-1);
- if (!num[0] || !num[1] || !num[2] || num[3])
+ if (!num[0] || !num[1] || !num[2] || num[3] ||
+ ft_check_digits(num[0]) || ft_check_digits(num[1]) ||
+ ft_check_digits(num[2]) || ft_atoi(num[0]) > 255 ||
+ ft_atoi(num[1]) > 255 || ft_atoi(num[2]) > 255)
{
ft_free_words(num, NULL);
return (-1);
@@ -74,7 +93,7 @@ ft_get_colors(int fd, t_win *wlist)
if (ft_get_c_color(line, words, wlist) < 0)
{
ft_free_words(words, line);
- return (-1);
+ return (ft_map_error(9, wlist));
}
return (0);
}