News:

Simutrans Forum Archive
A complete record of the old Simutrans Forum.

Array out of bounds in wayobj

Started by Dwachs, January 06, 2019, 12:02:36 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dwachs

I get the following compiler complaint:

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?
Parsley, sage, rosemary, and maggikraut.

Ters

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.

prissi

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?

Ters

Quote from: prissi on February 05, 2019, 06:23:45 AMbecause 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.