corrige deux bad read or write due au depassement de la taille de map, en ajoutant total_num dans la struct
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */
|
/* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/05/28 13:03:46 by hulamy ### ########.fr */
|
/* Updated: 2019/05/28 17:00:32 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ int check_same_tetri(t_fillist *list, int num)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
curr_tetri = list;
|
curr_tetri = list;
|
||||||
while (curr_tetri != NULL/* && list->dope[1]*/)
|
while (curr_tetri != NULL)
|
||||||
{
|
{
|
||||||
i = 0;
|
i = 0;
|
||||||
if (!(curr_tetri->memory =
|
if (!(curr_tetri->memory =
|
||||||
@@ -78,6 +78,7 @@ int check_same_tetri(t_fillist *list, int num)
|
|||||||
next_tetri->same = curr_tetri;
|
next_tetri->same = curr_tetri;
|
||||||
next_tetri = next_tetri->next;
|
next_tetri = next_tetri->next;
|
||||||
}
|
}
|
||||||
|
curr_tetri->total_num = num;
|
||||||
curr_tetri = curr_tetri->next;
|
curr_tetri = curr_tetri->next;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
|
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/05/28 11:26:25 by hulamy ### ########.fr */
|
/* Updated: 2019/05/28 17:27:17 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
void print_error(char *str)
|
void print_error(char *str)
|
||||||
{
|
{
|
||||||
write(1, str, ft_strlen(str));
|
write(1, str, ft_strlen(str));
|
||||||
// exit(1);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -31,22 +31,19 @@ void print_error(char *str)
|
|||||||
void print_error_extended(int error, int *dope)
|
void print_error_extended(int error, int *dope)
|
||||||
{
|
{
|
||||||
if (!dope[3])
|
if (!dope[3])
|
||||||
{
|
|
||||||
print_error("error\n");
|
print_error("error\n");
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
if (error == 1)
|
if (error == 1)
|
||||||
ft_putstr("error: File contains char other than '.','#' and '\\n'.\n");
|
print_error("error: File contains char other than '.','#' and '\\n'\n");
|
||||||
if (error == 2)
|
if (error == 2)
|
||||||
ft_putstr("error: File contains more than 2 '\\n' in a row.\n");
|
print_error("error: File contains more than 2 '\\n' in a row\n");
|
||||||
if (error == 3)
|
if (error == 3)
|
||||||
ft_putstr("error: File contains less than 1 tetrimino "
|
print_error("error: File contains less than 1 tetrimino "
|
||||||
"or more than 26.\n");
|
"or more than 26\n");
|
||||||
if (error == 4)
|
if (error == 4)
|
||||||
ft_putstr("error: Tetrimino has more or less than 4 #.\n");
|
print_error("error: Tetrimino has more or less than 4 #\n");
|
||||||
if (error == 5)
|
if (error == 5)
|
||||||
ft_putstr("error: Tetrimino # are not all connected.\n");
|
print_error("error: Tetrimino # are not all connected\n");
|
||||||
// exit(1);
|
print_error("error\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
|
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/05/28 10:44:43 by hulamy ### ########.fr */
|
/* Updated: 2019/05/28 17:27:44 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -144,10 +144,7 @@ int parse_input(char *input, t_fillist **list, int *dope)
|
|||||||
while (j < 19)
|
while (j < 19)
|
||||||
tetri[j++] = input[i++];
|
tetri[j++] = input[i++];
|
||||||
tetri[19] = '\0';
|
tetri[19] = '\0';
|
||||||
// "wrong tetrimino" utile ?
|
|
||||||
if (check_tetri_errors(tetri))
|
if (check_tetri_errors(tetri))
|
||||||
// print_error("error\n");
|
|
||||||
// print_error("error: Wrong tetrimino.\n");
|
|
||||||
print_error_extended(check_tetri_errors(tetri), dope);
|
print_error_extended(check_tetri_errors(tetri), dope);
|
||||||
add_to_list(tetri, list, letter++, dope);
|
add_to_list(tetri, list, letter++, dope);
|
||||||
while (input[i] && input[i] != '.' && input[i] != '#')
|
while (input[i] && input[i] != '.' && input[i] != '#')
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
|
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/05/27 19:46:54 by hulamy ### ########.fr */
|
/* Updated: 2019/05/28 17:02:19 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
|
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/05/28 11:56:18 by hulamy ### ########.fr */
|
/* Updated: 2019/05/28 17:33:43 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -36,7 +36,9 @@ unsigned int fit_in_place(unsigned int *map, t_fillist *lst, int size, int i)
|
|||||||
return (0);
|
return (0);
|
||||||
if (r >= 32 && ++n)
|
if (r >= 32 && ++n)
|
||||||
r -= 32;
|
r -= 32;
|
||||||
tmp = (mask & (map[n] << r)) | (mask & (map[n + 1] >> (32 - r)));
|
tmp = (mask & (map[n] << r));
|
||||||
|
if (n + 1 < lst->total_num)
|
||||||
|
tmp |= (mask & (map[n + 1] >> (32 - r)));
|
||||||
tetri <<= lst->width;
|
tetri <<= lst->width;
|
||||||
r += size;
|
r += size;
|
||||||
}
|
}
|
||||||
@@ -94,7 +96,7 @@ void add_remove(unsigned int *map, t_fillist *list, int size)
|
|||||||
while (j >= list->position)
|
while (j >= list->position)
|
||||||
{
|
{
|
||||||
map[(j - 1) / 32] ^= (mask & tetri << (16 + i)) >> (j - 1);
|
map[(j - 1) / 32] ^= (mask & tetri << (16 + i)) >> (j - 1);
|
||||||
if (map[(j - 1) / 32 + 1])
|
if ((j - 1) / 32 + 1 < list->total_num)
|
||||||
map[(j - 1) / 32 + 1] ^= (mask & tetri << (16 + i)) << (32 - j) << 1;
|
map[(j - 1) / 32 + 1] ^= (mask & tetri << (16 + i)) << (32 - j) << 1;
|
||||||
j -= size;
|
j -= size;
|
||||||
i -= list->width;
|
i -= list->width;
|
||||||
|
|||||||
4
fillit.h
4
fillit.h
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
|
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/05/28 12:15:39 by hulamy ### ########.fr */
|
/* Updated: 2019/05/28 16:51:44 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -52,7 +52,6 @@
|
|||||||
** place : position sur l'axe des abscisses de la map (position % size)
|
** place : position sur l'axe des abscisses de la map (position % size)
|
||||||
** rank : position de 1 a 32 dans l'int du tableau d'int (position % 32)
|
** rank : position de 1 a 32 dans l'int du tableau d'int (position % 32)
|
||||||
** num : memorise dans quel int du tableau on se trouve (position / 32)
|
** num : memorise dans quel int du tableau on se trouve (position / 32)
|
||||||
** total_num : le nombre d'int dans le tableau d'int
|
|
||||||
** test :
|
** test :
|
||||||
** letter :
|
** letter :
|
||||||
** dope :
|
** dope :
|
||||||
@@ -70,6 +69,7 @@ typedef struct s_fillist
|
|||||||
int place;
|
int place;
|
||||||
int rank;
|
int rank;
|
||||||
int num;
|
int num;
|
||||||
|
int total_num;
|
||||||
int test;
|
int test;
|
||||||
char letter;
|
char letter;
|
||||||
int *dope;
|
int *dope;
|
||||||
|
|||||||
9
main.c
9
main.c
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
|
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/05/27 18:21:58 by hulamy ### ########.fr */
|
/* Updated: 2019/05/28 17:26:07 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -83,12 +83,7 @@ int main(int ac, char **av)
|
|||||||
if (ac == 2 || mdp)
|
if (ac == 2 || mdp)
|
||||||
{
|
{
|
||||||
if (!(input = read_file(av[1])))
|
if (!(input = read_file(av[1])))
|
||||||
{
|
print_error(dope[3] ? "error: Could not read file.\n" : "error\n");
|
||||||
if (dope[3])
|
|
||||||
print_error("error: Could not read file.\n");
|
|
||||||
else
|
|
||||||
print_error("error\n");
|
|
||||||
}
|
|
||||||
check_file_errors(input, dope);
|
check_file_errors(input, dope);
|
||||||
size = parse_input(input, &list, dope);
|
size = parse_input(input, &list, dope);
|
||||||
print_final_map(list, size);
|
print_final_map(list, size);
|
||||||
|
|||||||
Reference in New Issue
Block a user