From 6000629c17011395e2c8a73989be17bce41b5586 Mon Sep 17 00:00:00 2001 From: Philippe BLAGOJEVIC Date: Wed, 4 May 2022 16:53:38 +0200 Subject: [PATCH] Fixed RGB parsing --- Makefile | 2 +- libs/libft/srcs/ft_atoi.c | 6 +++++- maps/map_valid_03.cub | 2 +- srcs/parsing/check_rgb.c | 16 ++-------------- srcs/parsing/init_parsing.c | 12 +++--------- 5 files changed, 12 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index cbcaf0e..6e7929b 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,7 @@ RM_OBJS = rm -rf $(D_OBJS) # flags CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -CFLAGS += -g3 -fsanitize=address +CFLAGS += -g3 LFLAGS = -L$(D_LFT) -lft LFLAGS += -L$(D_LMLX) -lm -lmlx -lXext -lX11 diff --git a/libs/libft/srcs/ft_atoi.c b/libs/libft/srcs/ft_atoi.c index 778f21e..2e9324c 100644 --- a/libs/libft/srcs/ft_atoi.c +++ b/libs/libft/srcs/ft_atoi.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/25 13:54:29 by hulamy #+# #+# */ -/* Updated: 2022/05/04 14:09:01 by pblagoje ### ########.fr */ +/* Updated: 2022/05/04 16:44:26 by pblagoje ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,5 +29,9 @@ int ft_atoi(const char *str) i++; while (str[i] >= '0' && str[i] <= '9') nbr = nbr * 10 + (str[i++] - '0'); + while ((str[i] == ' ') || (str[i] > 8 && str[i] < 14)) + i++; + if (str[i] != '\0') + return (-1); return (nbr * negatif); } diff --git a/maps/map_valid_03.cub b/maps/map_valid_03.cub index 706c7a0..861d42c 100644 --- a/maps/map_valid_03.cub +++ b/maps/map_valid_03.cub @@ -4,7 +4,7 @@ WE ./textures/wood.xpm EA ./textures/blue.xpm F 66, 66 , 66 -C 33,33 ,33 +C 33 , 5 55 , 33 111111111111111111111111 100000000000000000000001 diff --git a/srcs/parsing/check_rgb.c b/srcs/parsing/check_rgb.c index 09d6b90..c809ed5 100644 --- a/srcs/parsing/check_rgb.c +++ b/srcs/parsing/check_rgb.c @@ -6,7 +6,7 @@ /* By: pblagoje +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/04/15 16:11:24 by pblagoje #+# #+# */ -/* Updated: 2022/05/04 12:58:13 by pblagoje ### ########.fr */ +/* Updated: 2022/05/04 16:46:11 by pblagoje ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,19 +51,6 @@ static void set_rgb(int *plan, char **rgb) *plan = 0 << 24 | r << 16 | g << 8 | b; } -/*void ft_free_2d(char **str) -{ - int i; - - i = 0; - while (str && str[i]) - { - free(str[i]); - i++; - } - free(str); -}*/ - int check_rgb(t_txt *txt, char *elem, char identifier) { char **rgb; @@ -78,5 +65,6 @@ int check_rgb(t_txt *txt, char *elem, char identifier) set_rgb(&txt->rgb_floor, rgb); else set_rgb(&txt->rgb_ceiling, rgb); + mb_free_2d((void **)rgb, ft_strlen_2d(rgb)); return (EXIT_SUCCESS); } diff --git a/srcs/parsing/init_parsing.c b/srcs/parsing/init_parsing.c index 3335f29..35c68d2 100644 --- a/srcs/parsing/init_parsing.c +++ b/srcs/parsing/init_parsing.c @@ -6,7 +6,7 @@ /* By: pblagoje +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/04/15 16:03:50 by pblagoje #+# #+# */ -/* Updated: 2022/05/04 13:14:21 by pblagoje ### ########.fr */ +/* Updated: 2022/05/04 15:32:54 by pblagoje ### ########.fr */ /* */ /* ************************************************************************** */ @@ -89,10 +89,7 @@ int fill_map(t_map *map, int fd) map->content = (char **)mb_alloc((map->size_y + 1) * sizeof(char *)); if (!map->content) - { - mb_free(map->tmp_str); - return (EXIT_FAILURE); - } + mb_exit("Error\nCouldn't allocate memory for map.\n", EXIT_FAILURE); i = -1; while (++i < map->size_y) { @@ -103,10 +100,7 @@ int fill_map(t_map *map, int fd) } map->content[i] = (char *)mb_alloc((map->size_x + 1) * sizeof(char)); if (!map->content[i]) - { - mb_free(map->tmp_str); - return (EXIT_FAILURE); - } + mb_exit("Error\nCouldn't allocate memory for row.\n", EXIT_FAILURE); fill_row(map->content[i], map->tmp_str, map->size_x); mb_free(map->tmp_str); map->tmp_str = NULL;