The International Simutrans Forum

 

Author Topic: Array out of bounds in wayobj  (Read 843 times)

0 Members and 1 Guest are viewing this topic.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4603
  • Languages: EN, DE, AT
Array out of bounds in wayobj
« on: January 06, 2019, 12:02:36 PM »
I get the following compiler complaint:
Code: [Select]
obj/../descriptor/way_obj_desc.h: In member function 'virtual image_id wayobj_t::get_image() const':
obj/../descriptor/way_obj_desc.h:64:52: warning: array subscript is above array bounds [-Warray-bounds]
    return imglist->get_image_id( ribi_to_extra[ribi]+16+(nw*5) );
The reason is the following: in wayobj_t::get_image the method get_crossing_image_id is called with parameter ``dir'' if dir is larger than 16, which is out-of-bounds. Is there some masking missing?

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5543
  • Languages: EN, NO
Re: Array out of bounds in wayobj
« Reply #1 on: January 06, 2019, 04:26:18 PM »
The code in question was committed by prissi in August along with changes related to sound. The commit message only mentions sound. I suspect that get_crossing_image_id is unfinished code that was committed by mistake.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9568
  • Languages: De,EN,JP
Re: Array out of bounds in wayobj
« Reply #2 on: February 05, 2019, 06:23:45 AM »
This was part of an effort of having directional wayobj (like highway entries, overhead wires no ending in middle tile). It should not be a problem, because normal wayobj only have 16 ribis and ribi itself cannot exceed 15 (all directions). Maybe the warning occurs, because ribi is unsigned char?

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5543
  • Languages: EN, NO
Re: Array out of bounds in wayobj
« Reply #3 on: February 05, 2019, 06:38:55 AM »
because normal wayobj only have 16 ribis and ribi itself cannot exceed 15
Then why does it only call get_crossing_image_id if ribi>16? It appears that ribi_to_extra can not possibly be accessed within bounds, although I only checked usages of get_crossing_image_id from wayobj_t.