Browse Source

lab_can_move y undefined below 0 (overflow)

main^2
Joe Lukas Kalb 11 months ago
committed by Peter Wiebe
parent
commit
92f2f74c3e
  1. 2
      src/main/c/labyrinth.c
  2. 31
      src/test/c/test_labyrinth.c

2
src/main/c/labyrinth.c

@ -61,7 +61,7 @@ short lab_can_move(Field_State** field, unsigned short x, unsigned short y, Dire
if (x >= len_x){
return 1;
}
if (y == 1){
if (y >= len_y){
return 1;
}

31
src/test/c/test_labyrinth.c

@ -445,6 +445,37 @@ void test_lab_can_move_at_0_0_direction_S_target_undefined_expected_1(void)
free(field);
}
void test_lab_can_move_at_0_0_direction_W_target_undefined_expected_1(void)
{
/* arrange */
unsigned short x = 0;
unsigned short y = 0;
Direction direction = W;
short expected = 1;
short actual;
unsigned short len_x = 1, len_y = 1;
Field_State **field;
field = malloc(len_x * sizeof *field);
for (int c_index = 0; c_index < len_x; c_index++){
field[c_index] = malloc(len_y * sizeof field[c_index]);
}
/* act */
actual = lab_can_move(field, x, y, direction, len_x, len_y);
/* assert */
TEST_ASSERT_EQUAL_INT8(expected, actual);
for (int c_index = 0; c_index < len_x; c_index++)
{
free(field[c_index]);
}
free(field);
}
Loading…
Cancel
Save