[RTEMS Project] #2923: Questionable Code in resource_snapshot.c

RTEMS trac trac at rtems.org
Tue Mar 14 06:28:40 UTC 2017


#2923: Questionable Code in resource_snapshot.c
---------------------------+------------------------------
 Reporter:  Joel Sherrill  |       Owner:  Sebastian Huber
     Type:  defect         |      Status:  assigned
 Priority:  normal         |   Milestone:  4.12
Component:  cpukit         |     Version:  4.12
 Severity:  normal         |  Resolution:
 Keywords:                 |
---------------------------+------------------------------

Comment (by Sebastian Huber):

 Replying to [comment:3 Gedare]:
 > Very ugly. The hack might be a bit more clear if we use
 >
 > {{{
 >
 > typedef struct {
 >   Heap_Information_block workspace_info;
 >   Heap_Information_block heap_info;
 >   uint32_t active_posix_key_value_pairs;
 >   union {
 >     uint32_t anonymous[ 1 + ( sizeof(rtems_resource_rtems_api) +
 sizeof(rtems_resource_posix_api) ) / sizeof(uint32_t) ];
 >     struct {
 >       uint32_t active_posix_keys;
 >       rtems_resource_rtems_api rtems_api;
 >       rtems_resource_posix_api posix_api;
 >     }
 >   }
 >   int open_files;
 > } rtems_resource_snapshot;
 > }}}

 The rtems_resource_snapshot structure is supposed to be easy to understand
 for the user and should not make implementation details visible. With the
 union you still assume a certain mapping of array elements and normal
 structure members. It is an out-of-bounds access, so Coverity is right,
 but it is intentional. I don't think this should be changed.

--
Ticket URL: <http://devel.rtems.org/ticket/2923#comment:4>
RTEMS Project <http://www.rtems.org/>
RTEMS Project


More information about the bugs mailing list