Actions
Bug #13585
closedstmf: array subscript is above array bounds
Start date:
Due date:
% Done:
100%
Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:
Description
Build errors with gcc 10:
../../common/io/comstar/stmf/lun_map.c: In function 'stmf_session_prepare_report_lun_data': ../../common/io/comstar/stmf/lun_map.c:279:10: error: array subscript 9 is above array bounds of ' uint8_t[4]' {aka 'unsigned char[4]'} [-Werror=array-bounds] 279 | xd->buf[8 + (ent << 3) + 1] = (uchar_t)i; | ~~~~~~~^~~~~~~~~~~~~~~~~~~~ In file included from ../../common/io/comstar/stmf/lun_map.c:41: ../../common/io/comstar/stmf/stmf_impl.h:423:11: note: while referencing 'buf' 423 | uint8_t buf[4]; | ^~~ ../../common/io/comstar/stmf/lun_map.c:280:10: error: array subscript 8 is above array bounds of ' uint8_t[4]' {aka 'unsigned char[4]'} [-Werror=array-bounds] 280 | xd->buf[8 + (ent << 3) + 0] = ((uchar_t)(i >> 8)); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~ In file included from ../../common/io/comstar/stmf/lun_map.c:41: ../../common/io/comstar/stmf/stmf_impl.h:423:11: note: while referencing 'buf' 423 | uint8_t buf[4]; | ^~~ cc1: all warnings being treated as errors *** Error code 1 dmake: Warning: Command failed for target `obj64/lun_map.o' Current working directory /code/illumos-gate/usr/src/uts/intel/stmf
The problem is about the structure field uint8_t buf4, which is used as if uint8_t buf[]. The compiler knows the allocation size and does warn about going past array end. The right approach would be to use flexible array there, but at this point I do not know why the size 4 was used there.
Updated by Electric Monk over 1 year ago
- Status changed from In Progress to Closed
- % Done changed from 90 to 100
git commit 8ad466288742ffe497149f668ec1c028def2c686
commit 8ad466288742ffe497149f668ec1c028def2c686 Author: Toomas Soome <tsoome@me.com> Date: 2021-03-01T08:51:39.000Z 13585 stmf: array subscript is above array bounds Reviewed by: C Fraire <cfraire@me.com> Reviewed by: Andy Fiddaman <andy@omniosce.org> Approved by: Dan McDonald <danmcd@joyent.com>
Actions