nasa / CF

The Core Flight System (cFS) CFDP application.
Apache License 2.0
79 stars 45 forks source link

CF odd use of macro in CF_CFDP_R2_CalcCrcChunk #63

Closed jphickey closed 2 years ago

jphickey commented 2 years ago

This issue was imported from the GSFC issue tracking system

Imported from: [GSFCCFS-1800] CF odd use of macro in CF_CFDP_R2_CalcCrcChunk Originally submitted by: Hickey, Joseph P. (GSFC-582.0)[VANTAGE SYSTEMS INC] on Wed Nov 17 10:25:30 2021

Original Description: This function appears to define a local macro inline just to avoid writing the same text a few times over. Example:

define RXC t->state_data.r.r2.rx_crc_calc_bytes

    if (!RXC)
    {
        CF_CRC_Start(&t->crc);
    }

The "RXC" is then used in a number of places later as well.

Normally one would either declare a local pointer to the value, or just simply a local temp variable to hold the value during computation, updating the global at the end of the routine.

The major issue with a macro like this is that it is not scoped to this function. The "RXC" string remains defined as a macro after this function, and may unexpectedly replace any other occurrence of this symbol later in the file, should it ever appear.

jphickey commented 2 years ago

The specific instance of "RXC" described here was fixed by PR #137.

However, there are other instances of #define occurring at random locations within source files that should be fixed.