The International Simutrans Forum

Development => Bug Reports => Topic started by: Dwachs on January 06, 2019, 12:02:36 PM

Title: Array out of bounds in wayobj
Post by: Dwachs 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?
Title: Re: Array out of bounds in wayobj
Post by: Ters 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.
Title: Re: Array out of bounds in wayobj
Post by: prissi 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?
Title: Re: Array out of bounds in wayobj
Post by: Ters 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.