Skip to content

Odd union for ack/nak counters #113

@jphickey

Description

@jphickey

Union is declared here:

CF/fsw/src/cf_cfdp.h

Lines 137 to 141 in a894069

typedef union CF_RxTxCounters
{
unsigned ack;
uint8 nak;
} CF_RxTxCounters_t;

This counter is then used in the TxS2/RxS2 state data structures.

It should not be necessary to create a union between the unsigned and uint8 types for two reasons:

  • unsigned is not a known/guaranteed range type, and the rollover point of this value is not guaranteed. FSW discourages use of types which do not have fixed range unless for valid reasons (e.g. interfacing with library code that uses this type)
  • uint8 is simply the 8 LSBs of the value, there is no need to unionize in order to be able to count both modulo 256 as well as a longer type

In short, declaring a union like this has no benefit at all, but only introduces the possibility of accessing it wrong and getting undefined behavior. Only downsides, no upside.

Recommendation is to replace with a normal uint32 counter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions