diff options
Diffstat (limited to '')
-rw-r--r-- | libft/inc/libft.h | 2 | ||||
-rw-r--r-- | libft/src/ft_dprintf.c | 6 | ||||
-rw-r--r-- | libft/src/ft_memdel.c | 6 | ||||
-rw-r--r-- | libft/src/ft_printf.c | 6 | ||||
-rw-r--r-- | libft/src/ft_printf_flag_to_atoi.c | 2 | ||||
-rw-r--r-- | libft/src/ft_printf_get_flags.c | 2 | ||||
-rw-r--r-- | libft/src/ft_printf_get_width_nstr.c | 2 | ||||
-rw-r--r-- | libft/src/ft_printf_parts.c | 2 | ||||
-rw-r--r-- | libft/src/ft_printf_put_hex.c | 4 | ||||
-rw-r--r-- | libft/src/ft_printf_put_int.c | 4 | ||||
-rw-r--r-- | libft/src/ft_printf_put_precision.c | 2 | ||||
-rw-r--r-- | libft/src/ft_printf_put_ptr.c | 2 | ||||
-rw-r--r-- | libft/src/ft_printf_put_str.c | 2 | ||||
-rw-r--r-- | libft/src/ft_printf_put_width.c | 8 | ||||
-rw-r--r-- | libft/src/ft_printf_treat_flags.c | 2 | ||||
-rw-r--r-- | libft/src/ft_printf_use_flags.c | 2 | ||||
-rw-r--r-- | libft/src/ft_sprintf.c | 6 | ||||
-rw-r--r-- | src/ft_exit.c | 19 | ||||
-rw-r--r-- | src/ft_free_words.c | 4 | ||||
-rw-r--r-- | src/ft_get_map.c | 16 | ||||
-rw-r--r-- | src/ft_get_sprite.c | 2 | ||||
-rw-r--r-- | src/ft_get_tex.c | 8 | ||||
-rw-r--r-- | src/ft_init_lists.c | 2 | ||||
-rw-r--r-- | src/ft_init_winlx.c | 4 | ||||
-rw-r--r-- | src/ft_parse_map.c | 8 | ||||
-rw-r--r-- | src/main.c | 6 |
26 files changed, 66 insertions, 63 deletions
diff --git a/libft/inc/libft.h b/libft/inc/libft.h index 58dbbc2..4799121 100644 --- a/libft/inc/libft.h +++ b/libft/inc/libft.h @@ -68,7 +68,7 @@ void ft_lstiter(t_list *lst, void (*f)(void *)); void ft_kernel_panic(void); void ft_putnbr(long nb); void ft_putnbr_base(long nb, char *base); -void ft_memdel(void *ptr); +void ft_memdel(void **ptr); void *ft_memset(void *b, int c, size_t len); void *ft_memcpy(void *dst, const void *src, size_t n); void *ft_memccpy(void *dst, const void *src, diff --git a/libft/src/ft_dprintf.c b/libft/src/ft_dprintf.c index d9f69c1..a717df5 100644 --- a/libft/src/ft_dprintf.c +++ b/libft/src/ft_dprintf.c @@ -23,9 +23,9 @@ static int int ret; ret = write(fd, pflist->output, pflist->fulllen); - ft_memdel(pflist->output); - ft_memdel(pflist->fullflag); - ft_memdel(pflist); + ft_memdel((void**)&pflist->output); + ft_memdel((void**)&pflist->fullflag); + ft_memdel((void**)&pflist); return (ret); } diff --git a/libft/src/ft_memdel.c b/libft/src/ft_memdel.c index 05c2982..a15e494 100644 --- a/libft/src/ft_memdel.c +++ b/libft/src/ft_memdel.c @@ -14,8 +14,8 @@ #include <stdlib.h> void - ft_memdel(void *ptr) + ft_memdel(void **ptr) { - free(ptr); - ptr = NULL; + free(*ptr); + *ptr = NULL; } diff --git a/libft/src/ft_printf.c b/libft/src/ft_printf.c index 747f516..a37d76e 100644 --- a/libft/src/ft_printf.c +++ b/libft/src/ft_printf.c @@ -23,9 +23,9 @@ static int int ret; ret = write(1, pflist->output, pflist->fulllen); - ft_memdel(pflist->output); - ft_memdel(pflist->fullflag); - ft_memdel(pflist); + ft_memdel((void**)&pflist->output); + ft_memdel((void**)&pflist->fullflag); + ft_memdel((void**)&pflist); return (ret); } diff --git a/libft/src/ft_printf_flag_to_atoi.c b/libft/src/ft_printf_flag_to_atoi.c index f75a7f7..f6b2d8a 100644 --- a/libft/src/ft_printf_flag_to_atoi.c +++ b/libft/src/ft_printf_flag_to_atoi.c @@ -29,6 +29,6 @@ char len = ft_strlchr(str, ' '); nnstr = ft_substr(str, 0, len); nstr = ft_strjoin(nnstr, str + len + 1); - ft_memdel(nnstr); + ft_memdel((void**)&nnstr); return (nstr); } diff --git a/libft/src/ft_printf_get_flags.c b/libft/src/ft_printf_get_flags.c index 80ee47c..8dffd9a 100644 --- a/libft/src/ft_printf_get_flags.c +++ b/libft/src/ft_printf_get_flags.c @@ -36,7 +36,7 @@ char if (!(fullflag = (char*)malloc((i + 1) * sizeof(char)))) return (NULL); ft_memcpy(fullflag, nstr = ft_substr(format, pos + 1, i), i); - ft_memdel(nstr); + ft_memdel((void**)&nstr); fullflag[i] = '\0'; pflist->actconv = *(format + pos + i + 1); return (fullflag); diff --git a/libft/src/ft_printf_get_width_nstr.c b/libft/src/ft_printf_get_width_nstr.c index 15b9f98..cb1b665 100644 --- a/libft/src/ft_printf_get_width_nstr.c +++ b/libft/src/ft_printf_get_width_nstr.c @@ -31,7 +31,7 @@ int { str = ft_printf_flag_to_atoi(pflist->fullflag); ret = ft_atoi(str); - ft_memdel(str); + ft_memdel((void**)&str); } else { diff --git a/libft/src/ft_printf_parts.c b/libft/src/ft_printf_parts.c index 55a48dd..8c83936 100644 --- a/libft/src/ft_printf_parts.c +++ b/libft/src/ft_printf_parts.c @@ -37,7 +37,7 @@ int int ret; ft_printf_cat_output(nstr = ft_substr(format, start, len), len, pflist); - ft_memdel(nstr); + ft_memdel((void**)&nstr); ret = 0; return (ret); } diff --git a/libft/src/ft_printf_put_hex.c b/libft/src/ft_printf_put_hex.c index bbf9821..f204bf1 100644 --- a/libft/src/ft_printf_put_hex.c +++ b/libft/src/ft_printf_put_hex.c @@ -55,7 +55,7 @@ void { str = ft_uitoa_base(x, FT_MIN_HEX_BASE); ft_printf_cat_output(str, ft_strlen(str), pflist); - ft_memdel(str); + ft_memdel((void**)&str); } ft_printf_put_width_post(pflist); } @@ -80,7 +80,7 @@ void { str = ft_uitoa_base(x, FT_MAJ_HEX_BASE); ft_printf_cat_output(str, ft_strlen(str), pflist); - ft_memdel(str); + ft_memdel((void**)&str); } ft_printf_put_width_post(pflist); } diff --git a/libft/src/ft_printf_put_int.c b/libft/src/ft_printf_put_int.c index ddf06b7..6aaa49f 100644 --- a/libft/src/ft_printf_put_int.c +++ b/libft/src/ft_printf_put_int.c @@ -87,7 +87,7 @@ void { str = ft_itoa(d); ft_printf_cat_output(str, ft_strlen(str), pflist); - ft_memdel(str); + ft_memdel((void**)&str); } ft_printf_put_width_post(pflist); } @@ -109,7 +109,7 @@ void { str = ft_uitoa(d); ft_printf_cat_output(str, ft_strlen(str), pflist); - ft_memdel(str); + ft_memdel((void**)&str); } ft_printf_put_width_post(pflist); } diff --git a/libft/src/ft_printf_put_precision.c b/libft/src/ft_printf_put_precision.c index 7898102..cc237fa 100644 --- a/libft/src/ft_printf_put_precision.c +++ b/libft/src/ft_printf_put_precision.c @@ -61,7 +61,7 @@ int str = ft_memset(str, '0', len); *(str + len) = '\0'; ft_printf_cat_output(str, ft_strlen(str), pflist); - ft_memdel(str); + ft_memdel((void**)&str); } return (0); } diff --git a/libft/src/ft_printf_put_ptr.c b/libft/src/ft_printf_put_ptr.c index 409847d..9ee7636 100644 --- a/libft/src/ft_printf_put_ptr.c +++ b/libft/src/ft_printf_put_ptr.c @@ -37,7 +37,7 @@ void { str = ft_uitoa_base(p, FT_MIN_HEX_BASE); ft_printf_cat_output(str, ft_strlen(str), pflist); - ft_memdel(str); + ft_memdel((void**)&str); } ft_printf_put_width_post(pflist); } diff --git a/libft/src/ft_printf_put_str.c b/libft/src/ft_printf_put_str.c index a11128b..dcb732c 100644 --- a/libft/src/ft_printf_put_str.c +++ b/libft/src/ft_printf_put_str.c @@ -32,7 +32,7 @@ void { ft_printf_cat_output(nstr = ft_substr(str, 0, pflist->putlen), pflist->putlen, pflist); - ft_memdel(nstr); + ft_memdel((void**)&nstr); } else ft_printf_cat_output(str, pflist->putlen, pflist); diff --git a/libft/src/ft_printf_put_width.c b/libft/src/ft_printf_put_width.c index 30ae97f..d201e82 100644 --- a/libft/src/ft_printf_put_width.c +++ b/libft/src/ft_printf_put_width.c @@ -61,7 +61,7 @@ void str = ft_memset(str, ' ', ft_printf_get_len(pflist)); *(str + ft_printf_get_len(pflist)) = '\0'; ft_printf_cat_output(str, ft_strlen(str), pflist); - ft_memdel(str); + ft_memdel((void**)&str); } else if (pflist->conv == 's' && pflist->width - pflist->putlen > 0 && !pflist->isreverse) @@ -71,7 +71,7 @@ void str = ft_memset(str, ' ', ft_printf_get_len(pflist)); *(str + ft_printf_get_len(pflist)) = '\0'; ft_printf_cat_output(str, ft_strlen(str), pflist); - ft_memdel(str); + ft_memdel((void**)&str); } } @@ -89,7 +89,7 @@ void str = ft_memset(str, ' ', ft_printf_get_len(pflist)); *(str + ft_printf_get_len(pflist)) = '\0'; ft_printf_cat_output(str, ft_strlen(str), pflist); - ft_memdel(str); + ft_memdel((void**)&str); } else if (pflist->conv == 's' && pflist->width - pflist->putlen > 0 && pflist->isreverse) @@ -100,6 +100,6 @@ void str = ft_memset(str, ' ', ft_printf_get_len(pflist)); *(str + ft_printf_get_len(pflist)) = '\0'; ft_printf_cat_output(str, ft_strlen(str), pflist); - ft_memdel(str); + ft_memdel((void**)&str); } } diff --git a/libft/src/ft_printf_treat_flags.c b/libft/src/ft_printf_treat_flags.c index cb60c19..8beebca 100644 --- a/libft/src/ft_printf_treat_flags.c +++ b/libft/src/ft_printf_treat_flags.c @@ -30,7 +30,7 @@ static int nstr_ptr = nstr; nstr = ft_printf_get_width_nstr(nstr, pflist); ret = ft_printf_fetch_width(arg, nstr, pflist); - ft_memdel(nstr_ptr); + ft_memdel((void**)&nstr_ptr); (ret < 0) ? (pflist->isreverse = 1) : 0; (ret < 0) ? (ret = -ret) : 0; return (ret); diff --git a/libft/src/ft_printf_use_flags.c b/libft/src/ft_printf_use_flags.c index 7b1299e..4646bc6 100644 --- a/libft/src/ft_printf_use_flags.c +++ b/libft/src/ft_printf_use_flags.c @@ -29,7 +29,7 @@ static void va_list arg, t_printflist *pflist) { - ft_memdel(pflist->fullflag); + ft_memdel((void**)&pflist->fullflag); pflist->fullflag = ft_printf_get_flags(format, pos, pflist); ft_printf_treat_flags(arg, pflist); ft_printf_process(format + pos, arg, pflist); diff --git a/libft/src/ft_sprintf.c b/libft/src/ft_sprintf.c index 0cf5dc2..7cf0204 100644 --- a/libft/src/ft_sprintf.c +++ b/libft/src/ft_sprintf.c @@ -24,9 +24,9 @@ static int ft_strlcpy(str, pflist->output, pflist->fulllen + 1); ret = pflist->fulllen; - ft_memdel(pflist->output); - ft_memdel(pflist->fullflag); - ft_memdel(pflist); + ft_memdel((void**)&pflist->output); + ft_memdel((void**)&pflist->fullflag); + ft_memdel((void**)&pflist); return (ret); } diff --git a/src/ft_exit.c b/src/ft_exit.c index 8bd8ac0..6631c34 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -8,17 +8,18 @@ static void ft_free_lists(t_cub *clist) { - ft_memdel(clist->no_tex_path); - ft_memdel(clist->so_tex_path); - ft_memdel(clist->ea_tex_path); - ft_memdel(clist->we_tex_path); - ft_memdel(clist->sprite_path); + ft_memdel((void**)&clist->no_tex_path); + ft_memdel((void**)&clist->so_tex_path); + ft_memdel((void**)&clist->ea_tex_path); + ft_memdel((void**)&clist->we_tex_path); + ft_memdel((void**)&clist->sprite_path); + ft_memdel((void**)&clist->mapl); ft_free_words(clist->map); if (!clist->wlist->inited) - ft_memdel(clist->wlist->winptr); - ft_memdel(clist->wlist->wlx); - ft_memdel(clist->wlist); - ft_memdel(clist); + ft_memdel((void**)&clist->wlist->winptr); + ft_memdel((void**)&clist->wlist->wlx); + ft_memdel((void**)&clist->wlist); + ft_memdel((void**)&clist); } int diff --git a/src/ft_free_words.c b/src/ft_free_words.c index 3231791..1029710 100644 --- a/src/ft_free_words.c +++ b/src/ft_free_words.c @@ -8,8 +8,8 @@ ft_free_words(char **words) i = 0; while (words[i]) { - ft_memdel(words[i]); + ft_memdel((void**)&words[i]); i++; } - ft_memdel(words); + ft_memdel((void**)&words); } diff --git a/src/ft_get_map.c b/src/ft_get_map.c index 3844f41..adedf7c 100644 --- a/src/ft_get_map.c +++ b/src/ft_get_map.c @@ -40,22 +40,22 @@ ft_get_map_first_line(char *line, t_cub *clist) { if (!line[0]) { - ft_memdel(line); + ft_memdel((void**)&line); return (-1); } clist->map_w = ft_get_line_len(line); if (ft_check_map_line(line, 1, clist) < 0) { - ft_memdel(line); + ft_memdel((void**)&line); return (-1); } - clist->mapl = NULL; + ft_memdel((void**)&clist->mapl); if (ft_cat_mapl(line, 0, clist) < 0) { - ft_memdel(line); + ft_memdel((void**)&line); return (-1); } - ft_memdel(line); + ft_memdel((void**)&line); return (1); } @@ -75,15 +75,15 @@ ft_get_map_core(int fd, t_cub *clist) if (!line[0] || ft_check_map_line(line, 0, clist) < 0 || ft_cat_mapl(line, i, clist) < 0) { - ft_memdel(line); + ft_memdel((void**)&line); return (-1); } - ft_memdel(line); + ft_memdel((void**)&line); i++; } clist->mapl[((clist->map_w + 1) * i) - 1] = '\0'; ft_free_words(clist->map); clist->map = ft_split(clist->mapl, '\n'); - ft_memdel(clist->mapl); + ft_memdel((void**)&clist->mapl); return (0); } diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index b412442..b588df7 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -6,7 +6,7 @@ ft_get_sprite(char **words, t_cub *clist) { if (!(*words) || !words[1] || words[2]) return (-1); - ft_memdel(clist->sprite_path); + ft_memdel((void**)&clist->sprite_path); if (!(clist->sprite_path = ft_strdup(*(words + 1)))) return (-1); return (0); diff --git a/src/ft_get_tex.c b/src/ft_get_tex.c index 3c0f305..5b8e24e 100644 --- a/src/ft_get_tex.c +++ b/src/ft_get_tex.c @@ -7,7 +7,7 @@ ft_get_tex_no(char **words, t_cub *clist) { if (!(*words) || !(*(words + 1)) || (*(words + 2))) return (-1); - ft_memdel(clist->no_tex_path); + ft_memdel((void**)&clist->no_tex_path); if (!(clist->no_tex_path = ft_strdup(*(words + 1)))) return (-1); return (0); @@ -18,7 +18,7 @@ ft_get_tex_so(char **words, t_cub *clist) { if (!(*words) || !(*(words + 1)) || (*(words + 2))) return (-1); - ft_memdel(clist->so_tex_path); + ft_memdel((void**)&clist->so_tex_path); if (!(clist->so_tex_path = ft_strdup(*(words + 1)))) return (-1); return (0); @@ -29,7 +29,7 @@ ft_get_tex_ea(char **words, t_cub *clist) { if (!(*words) || !(*(words + 1)) || (*(words + 2))) return (-1); - ft_memdel(clist->ea_tex_path); + ft_memdel((void**)&clist->ea_tex_path); if (!(clist->ea_tex_path = ft_strdup(*(words + 1)))) return (-1); return (0); @@ -40,7 +40,7 @@ ft_get_tex_we(char **words, t_cub *clist) { if (!(*words) || !(*(words + 1)) || (*(words + 2))) return (-1); - ft_memdel(clist->we_tex_path); + ft_memdel((void**)&clist->we_tex_path); if (!(clist->we_tex_path = ft_strdup(*(words + 1)))) return (-1); return (0); diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 63357ec..285dbd8 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -32,6 +32,7 @@ t_cub !(clist->ea_tex_path = (char*)ft_calloc(1, sizeof(char))) || !(clist->we_tex_path = (char*)ft_calloc(1, sizeof(char))) || !(clist->sprite_path = (char*)ft_calloc(1, sizeof(char))) || + !(clist->mapl = (char*)ft_calloc(1, sizeof(char))) || !(clist->map = (char**)ft_calloc(2, sizeof(char*))) || !(clist->map[0] = (char*)ft_calloc(1, sizeof(char)))) return (NULL); @@ -40,5 +41,6 @@ t_cub clist->c_color = -1; clist->map_w = 0; clist->line_chk = 0; + clist->nsew = 0; return (clist); } diff --git a/src/ft_init_winlx.c b/src/ft_init_winlx.c index d45f19d..5706685 100644 --- a/src/ft_init_winlx.c +++ b/src/ft_init_winlx.c @@ -6,10 +6,10 @@ int ft_init_winlx(t_cub *clist) { - ft_memdel(clist->wlist->wlx); + ft_memdel((void**)&clist->wlist->wlx); if (!(clist->wlist->wlx = mlx_init())) return (-1); - ft_memdel(clist->wlist->winptr); + ft_memdel((void**)&clist->wlist->winptr); if (!(clist->wlist->winptr = mlx_new_window(clist->wlist->wlx, clist->wlist->x_size, clist->wlist->y_size, "Cub3D"))) return (-1); diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 77f3f47..cc4d920 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -60,17 +60,17 @@ ft_parse_it(int fd, t_cub *clist) return (ft_map_error(clist)); if (ret == 0) { - ft_memdel(line); + ft_memdel((void**)&line); return (ft_map_error(clist)); } if (!line[0]) { - ft_memdel(line); + ft_memdel((void**)&line); return (ft_parse_it(fd, clist)); } if (!(words = ft_split(line, ' '))) { - ft_memdel(line); + ft_memdel((void**)&line); return (ft_map_error(clist)); } if ((ret = ft_select_get(words, clist)) == 12) @@ -79,7 +79,7 @@ ft_parse_it(int fd, t_cub *clist) return (-1); return (12); } - ft_memdel(line); + ft_memdel((void**)&line); return (ret); } @@ -9,13 +9,13 @@ int if (!(clist = ft_init_cub())) { - ft_memdel(clist); + ft_memdel((void**)&clist); return (1); } if (!(clist->wlist = ft_init_win())) { - ft_memdel(clist->wlist); - ft_memdel(clist); + ft_memdel((void**)&clist->wlist); + ft_memdel((void**)&clist); return (1); } ft_parse_map("map/map_one.cub", clist); |