Login
User Name:

Password:



Register

Forgot your password?
void nanny_get_new_race -- comm.c
Feb 16, 2025 1:25 am
By Elwood
IPv6
Jan 25, 2025 10:45 pm
By Samson
mudstrlcpy and mudstrlcat
Jan 18, 2025 5:23 pm
By Samson
I3 and IMC
Jan 17, 2025 9:35 pm
By Samson
AFKMud 2.5.1
Jan 17, 2025 2:22 pm
By Samson
SmaugFUSS 1.9.7
Author: Various
Submitted by: Samson
AFKMud 2.5.1
Author: AFKMud Team
Submitted by: Samson
Kayle's Weather Code for AFKMud
Author: Kayle
Submitted by: Samson
AFKMud 2.5.0
Author: AFKMud Team
Submitted by: Samson
SWFotEFUSS 1.5.2
Author: Various
Submitted by: Samson
Users Online
CommonCrawl, AhrefsBot, Google, Bing

Members: 0
Guests: 9
Stats
Files
Topics
Posts
Members
Newest Member
503
3,812
19,715
590
iasiney

» SmaugMuds » Codebases » SmaugFUSS » Array out of bounds ?
Forum Rules | Mark all | Recent Posts

Array out of bounds ?
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Jan 14, 2025 10:00 pm   
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,706
JoinedJan 1, 2002

 
I ran a static analysis recently with cppcheck and it picked this up as an out of bound array access in the first set of for loops here. Specifically with board->board[x][y] = 0;

I can't figure out why that would be the case. The compiler doesn't flag it, and it doesn't set off the sanitization code either.

static void init_board( GAME_BOARD_DATA * board )
{
   int x, y;

   for( x = 0; x < 8; x++ )
      for( y = 0; y < 8; y++ )
         board->board[x][y] = 0;

   board->board[0][0] = WHITE_ROOK;
   board->board[0][1] = WHITE_KNIGHT;
   board->board[0][2] = WHITE_BISHOP;
   board->board[0][3] = WHITE_QUEEN;
   board->board[0][4] = WHITE_KING;
   board->board[0][5] = WHITE_BISHOP;
   board->board[0][6] = WHITE_KNIGHT;
   board->board[0][7] = WHITE_ROOK;

   for( x = 0; x < 8; x++ )
      board->board[1][x] = WHITE_PAWN;
   for( x = 0; x < 8; x++ )
      board->board[6][x] = BLACK_PAWN;

   board->board[7][0] = BLACK_ROOK;
   board->board[7][1] = BLACK_KNIGHT;
   board->board[7][2] = BLACK_BISHOP;
   board->board[7][3] = BLACK_QUEEN;
   board->board[7][4] = BLACK_KING;
   board->board[7][5] = BLACK_BISHOP;
   board->board[7][6] = BLACK_KNIGHT;
   board->board[7][7] = BLACK_ROOK;
   board->player1 = NULL;
   board->player2 = NULL;
   board->turn = 0;
   board->type = TYPE_LOCAL;
}

Post is unread #2 Jan 15, 2025 7:01 pm   
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,992
JoinedJul 26, 2005

 
it doesn't look bad but would it be happier if you did <= 7?

Post is unread #3 Jan 16, 2025 12:44 am   
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,706
JoinedJan 1, 2002

 
<=7 would be functionally equal to < 8 in this case.

Post is unread #4 Jan 16, 2025 4:48 am   
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,992
JoinedJul 26, 2005

 
I agree but never know sometimes that might make one not complain lol depends on what its looking for :) It would have been cool if it liked <= 7 but is complaining about < 8.

Pages:<< prev 1 next >>