aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-01-25 19:51:12 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-01-25 19:51:12 +0100
commitf2b7255587c5d24999fe5d471f480341f8162733 (patch)
tree8b9ab0ef2aa6e0b9434e253861d0f1c8fa783c9a
parentPretty bav (diff)
download42-cub3d-f2b7255587c5d24999fe5d471f480341f8162733.tar.gz
42-cub3d-f2b7255587c5d24999fe5d471f480341f8162733.tar.bz2
42-cub3d-f2b7255587c5d24999fe5d471f480341f8162733.tar.xz
42-cub3d-f2b7255587c5d24999fe5d471f480341f8162733.tar.zst
42-cub3d-f2b7255587c5d24999fe5d471f480341f8162733.zip
Better error management
-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);
}