Skip to main content
added 136 characters in body; Post Made Community Wiki
Source Link
chux
  • 33.7k
  • 2
  • 38
  • 92

Bug

uint8_t board[100]; ... for (uint8_t i = 1; i < 101; i++) { board[i] = i; } attempts to access board[100] which is out of the valid 0 - 99 range.

Better as

  #define BOARD_SIZE 100
  uint8_t board[BOARD_SIZE];
  ...
  for (size_t i = 0; i < BOARD_SIZE; i++) {
    board[i] = i + 1;
  }
 

[Edit]
Now I see this point lightly covered by TrayMan. Moving answer to wiki.

Bug

uint8_t board[100]; ... for (uint8_t i = 1; i < 101; i++) { board[i] = i; } attempts to access board[100] which is out of the valid 0 - 99 range.

Better as

  #define BOARD_SIZE 100
  uint8_t board[BOARD_SIZE];
  ...
  for (size_t i = 0; i < BOARD_SIZE; i++) {
    board[i] = i + 1;
  }
 

Bug

uint8_t board[100]; ... for (uint8_t i = 1; i < 101; i++) { board[i] = i; } attempts to access board[100] which is out of the valid 0 - 99 range.

Better as

  #define BOARD_SIZE 100
  uint8_t board[BOARD_SIZE];
  ...
  for (size_t i = 0; i < BOARD_SIZE; i++) {
    board[i] = i + 1;
  }

[Edit]
Now I see this point lightly covered by TrayMan. Moving answer to wiki.

Source Link
chux
  • 33.7k
  • 2
  • 38
  • 92

Bug

uint8_t board[100]; ... for (uint8_t i = 1; i < 101; i++) { board[i] = i; } attempts to access board[100] which is out of the valid 0 - 99 range.

Better as

  #define BOARD_SIZE 100
  uint8_t board[BOARD_SIZE];
  ...
  for (size_t i = 0; i < BOARD_SIZE; i++) {
    board[i] = i + 1;
  }