BlueMintCarrot / so_long

0 stars 0 forks source link

Segmentation Fault & Leaks #1

Open diogoforte opened 5 months ago

diogoforte commented 5 months ago

Some examples:

Map: 111111 1P0C01 101111 1000E1

Valgrind output: valgrind ./so_long maps/map2.ber ==292000== Memcheck, a memory error detector ==292000== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==292000== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info ==292000== Command: ./so_long maps/map2.ber ==292000== The map isn't surrounded by walls! ==292000== Invalid read of size 1 ==292000== at 0x11C52F: to_move_or_not_to_move (moves.c:116) ==292000== by 0x11C204: move_down (moves.c:68) ==292000== by 0x111636: where_is_the_bunny_going (bunny_movement.c:44) ==292000== by 0x11D015: mlx_loop (in /home/diogo/projects/solong_puta/so_long) ==292000== by 0x11C9E5: main (so_long.c:123) ==292000== Address 0x1 is not stack'd, malloc'd or (recently) free'd ==292000== ==292000== ==292000== Process terminating with default action of signal 11 (SIGSEGV) ==292000== Access not within mapped region at address 0x1 ==292000== at 0x11C52F: to_move_or_not_to_move (moves.c:116) ==292000== by 0x11C204: move_down (moves.c:68) ==292000== by 0x111636: where_is_the_bunny_going (bunny_movement.c:44) ==292000== by 0x11D015: mlx_loop (in /home/diogo/projects/solong_puta/so_long) ==292000== by 0x11C9E5: main (so_long.c:123) ==292000== If you believe this happened as a result of a stack ==292000== overflow in your program's main thread (unlikely but ==292000== possible), you can try to increase the size of the ==292000== main thread stack using the --main-stacksize= flag. ==292000== The main thread stack size used in this run was 8388608. ==292000== ==292000== HEAP SUMMARY: ==292000== in use at exit: 4,750,924 bytes in 18,833 blocks ==292000== total heap usage: 135,818 allocs, 116,985 frees, 15,665,890 bytes allocated ==292000== ==292000== LEAK SUMMARY: ==292000== definitely lost: 0 bytes in 0 blocks ==292000== indirectly lost: 0 bytes in 0 blocks ==292000== possibly lost: 0 bytes in 0 blocks ==292000== still reachable: 4,750,924 bytes in 18,833 blocks ==292000== suppressed: 0 bytes in 0 blocks ==292000== Rerun with --leak-check=full to see details of leaked memory ==292000== ==292000== For lists of detected and suppressed errors, rerun with: -s ==292000== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 26 from 1) [1] 292000 segmentation fault valgrind ./so_long maps/map2.ber

Map: PCE01

Valgrind output: valgrind ./so_long maps/map2.ber ==291310== Memcheck, a memory error detector ==291310== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==291310== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info ==291310== Command: ./so_long maps/map2.ber ==291310== ==291310== Invalid read of size 8 ==291310== at 0x11B56C: map_check2 (map_verifications.c:24) ==291310== by 0x11C621: map_manager (so_long.c:21) ==291310== by 0x11C7C2: final_map_check (so_long.c:61) ==291310== by 0x11C8C1: main (so_long.c:110) ==291310== Address 0x4d03610 is 0 bytes after a block of size 16 alloc'd ==291310== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==291310== by 0x11C6FA: create_map (so_long.c:46) ==291310== by 0x11C8A1: main (so_long.c:109) ==291310== ==291310== Invalid read of size 1 ==291310== at 0x11EECC: ft_strlen (in /home/diogo/projects/solong_puta/so_long) ==291310== by 0x11B592: map_check2 (map_verifications.c:33) ==291310== by 0x11C621: map_manager (so_long.c:21) ==291310== by 0x11C7C2: final_map_check (so_long.c:61) ==291310== by 0x11C8C1: main (so_long.c:110) ==291310== Address 0x0 is not stack'd, malloc'd or (recently) free'd ==291310== ==291310== ==291310== Process terminating with default action of signal 11 (SIGSEGV) ==291310== Access not within mapped region at address 0x0 ==291310== at 0x11EECC: ft_strlen (in /home/diogo/projects/solong_puta/so_long) ==291310== by 0x11B592: map_check2 (map_verifications.c:33) ==291310== by 0x11C621: map_manager (so_long.c:21) ==291310== by 0x11C7C2: final_map_check (so_long.c:61) ==291310== by 0x11C8C1: main (so_long.c:110) ==291310== If you believe this happened as a result of a stack ==291310== overflow in your program's main thread (unlikely but ==291310== possible), you can try to increase the size of the ==291310== main thread stack using the --main-stacksize= flag. ==291310== The main thread stack size used in this run was 8388608. ==291310== ==291310== HEAP SUMMARY: ==291310== in use at exit: 800,070 bytes in 3 blocks ==291310== total heap usage: 4 allocs, 1 frees, 800,072 bytes allocated ==291310== ==291310== LEAK SUMMARY: ==291310== definitely lost: 0 bytes in 0 blocks ==291310== indirectly lost: 0 bytes in 0 blocks ==291310== possibly lost: 0 bytes in 0 blocks ==291310== still reachable: 800,070 bytes in 3 blocks ==291310== suppressed: 0 bytes in 0 blocks ==291310== Rerun with --leak-check=full to see details of leaked memory ==291310== ==291310== For lists of detected and suppressed errors, rerun with: -s ==291310== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0) [1] 291310 segmentation fault valgrind ./so_long maps/map2.ber

Map: ola

Valgrind output: valgrind ./so_long maps/map2.ber ==293920== Memcheck, a memory error detector ==293920== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==293920== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info ==293920== Command: ./so_long maps/map2.ber ==293920== There are no collectibles available! There's no player available! ==293920== ==293920== HEAP SUMMARY: ==293920== in use at exit: 800,068 bytes in 3 blocks ==293920== total heap usage: 4 allocs, 1 frees, 800,070 bytes allocated ==293920== ==293920== LEAK SUMMARY: ==293920== definitely lost: 800,064 bytes in 2 blocks ==293920== indirectly lost: 4 bytes in 1 blocks ==293920== possibly lost: 0 bytes in 0 blocks ==293920== still reachable: 0 bytes in 0 blocks ==293920== suppressed: 0 bytes in 0 blocks ==293920== Rerun with --leak-check=full to see details of leaked memory ==293920== ==293920== For lists of detected and suppressed errors, rerun with: -s ==293920== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

dudsdeepz commented 5 months ago

You can find in the ducks.c some rather interesting names for the functions can you please explain in more detail the "fuck_the_duck" function and the "fuck_the_duck_once_more" function also

/* ** / / / / ::: :::::::: / / ducks.c :+: :+: :+: / / +:+ +:+ +:+ / / By: joana joana@student.42.fr +#+ +:+ +#+ / / +#+#+#+#+#+ +#+ / / Created: 2024/03/06 17:41:33 by joana #+# #+# / / Updated: 2024/03/06 18:54:26 by joana ### ########.fr / / / / ** */

include "so_long.h"

void ducks_captured(t_info *info) { static int c; static int w;

if (c == 0 && w == 0)
{
  c = 1;
  w = 128;
}
if (c == 1)
{
  mlx_put_image_to_window(info->vars->mlx, info->vars->window, \
  info->vars->imgs[71]->img, w, 0);
  c = 2;
}
else if (c == 2)
{
  mlx_put_image_to_window(info->vars->mlx, info->vars->window, \
  info->vars->imgs[72]->img, w, 0);
  w += 64;
  c = 1;
}

}

void fuck_the_duck(t_info info) { if (info->vars->map[info->y - 1][info->x] == 'C' && info->duck_direction == 4 && info->bunny_direction == 4) mlx_put_image_to_window(info->vars->mlx, info->vars->window, info->vars->imgs[16]->img, info->x 64, info->y 64 - 32); else if (info->vars->map[info->y - 1][info->x] == 'C' && info->duck_direction == 4 && info->bunny_direction == 6) mlx_put_image_to_window(info->vars->mlx, info->vars->window, info->vars->imgs[14]->img, info->x 64, info->y 64 - 32); else if (info->vars->map[info->y - 1][info->x] == 'C' && info->duck_direction == 6 && info->bunny_direction == 4) mlx_put_image_to_window(info->vars->mlx, info->vars->window, info->vars->imgs[15]->img, info->x 64, info->y 64 - 32); else if (info->vars->map[info->y - 1][info->x] == 'C' && info->duck_direction == 6 && info->bunny_direction == 6) mlx_put_image_to_window(info->vars->mlx, info->vars->window, info->vars->imgs[13]->img, info->x 64, info->y * 64 - 32); flame_animation(info); bat_animation(info); }

void fuck_the_duck_again(t_info info) { if (info->vars->map[info->y][info->x - 1] == 'C' && info->duck_direction == 4 && info->bunny_direction == 4) mlx_put_image_to_window(info->vars->mlx, info->vars->window, info->vars->imgs[24]->img, info->x 64 - 32, info->y 64); else if (info->vars->map[info->y][info->x - 1] == 'C' && info->duck_direction == 6 && info->bunny_direction == 4) mlx_put_image_to_window(info->vars->mlx, info->vars->window, info->vars->imgs[23]->img, info->x 64 - 32, info->y * 64); flame_animation(info); bat_animation(info); }

void fuck_the_duck_once_more(t_info info) { if (info->vars->map[info->y + 1][info->x] == 'C' && info->duck_direction == 4 && info->bunny_direction == 4) mlx_put_image_to_window(info->vars->mlx, info->vars->window, info->vars->imgs[20]->img, info->x 64, info->y 64 + 32); else if (info->vars->map[info->y + 1][info->x] == 'C' && info->duck_direction == 4 && info->bunny_direction == 6) mlx_put_image_to_window(info->vars->mlx, info->vars->window, info->vars->imgs[18]->img, info->x 64, info->y 64 + 32); else if (info->vars->map[info->y + 1][info->x] == 'C' && info->duck_direction == 6 && info->bunny_direction == 4) mlx_put_image_to_window(info->vars->mlx, info->vars->window, info->vars->imgs[19]->img, info->x 64, info->y 64 + 32); else if (info->vars->map[info->y + 1][info->x] == 'C' && info->duck_direction == 6 && info->bunny_direction == 6) mlx_put_image_to_window(info->vars->mlx, info->vars->window, info->vars->imgs[17]->img, info->x 64, info->y * 64 + 32); flame_animation(info); bat_animation(info); }

void im_tired_of_fucking_the_duck(t_info info) { if (info->vars->map[info->y][info->x + 1] == 'C' && info->duck_direction == 4 && info->bunny_direction == 6) mlx_put_image_to_window(info->vars->mlx, info->vars->window, info->vars->imgs[21]->img, info->x 64 + 32, info->y 64); else if (info->vars->map[info->y][info->x + 1] == 'C' && info->duck_direction == 6 && info->bunny_direction == 6) mlx_put_image_to_window(info->vars->mlx, info->vars->window, info->vars->imgs[22]->img, info->x 64 + 32, info->y * 64); flame_animation(info); bat_animation(info); }

我同意

Pedrocasss commented 5 months ago

Atenção aos nomes das funções...fuck the ducks?!!!