From c2260bad4aa6dd257ff94f22b15c0dd73da97af3 Mon Sep 17 00:00:00 2001 From: nicolas-arnaud Date: Sun, 20 Nov 2022 18:02:54 +0100 Subject: [PATCH] error if map extension isn't valid --- src/main.c | 2 ++ src/parsing/getline.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/main.c b/src/main.c index 030fdd7..43d152f 100644 --- a/src/main.c +++ b/src/main.c @@ -18,6 +18,8 @@ int main(int argc, char **argv) if (argc != 2) return (printf("Usage: ./cub3d mapfile.cub\n"), EXIT_FAILURE); + if (ft_strncmp(argv[1] + ft_strlen(argv[1]) - 4, ".cub", 4)) + return (printf("Wrong map file extension"), EXIT_FAILURE); env = load_map(argv[1]); if (!env) return (EXIT_FAILURE); diff --git a/src/parsing/getline.c b/src/parsing/getline.c index 264e870..9eb352d 100644 --- a/src/parsing/getline.c +++ b/src/parsing/getline.c @@ -40,6 +40,8 @@ char *get_next_line(const int fd) char *ret; char *next; + if (fd == -1) + return (NULL); if (!*buffer) buffer[read(fd, buffer, BUFFER_SIZE)] = 0; ret = ft_calloc(1, sizeof(char));