Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible uninitialized variables - compiler warnings (release build, CentOS 7) #1189

Closed
skliper opened this issue Mar 1, 2021 · 1 comment · Fixed by #1197 or #1196
Closed

Possible uninitialized variables - compiler warnings (release build, CentOS 7) #1189

skliper opened this issue Mar 1, 2021 · 1 comment · Fixed by #1197 or #1196
Assignees
Milestone

Comments

@skliper
Copy link
Contributor

skliper commented Mar 1, 2021

Is your feature request related to a problem? Please describe.
Various warnings on CentOS 7 when BUILDTYPE=release:

/home/jhageman/cFS/cFS-GitHub/cfe/fsw/cfe-core/src/sb/cfe_sb_api.c: In function ‘CFE_SB_TransmitMsg’:
/home/jhageman/cFS/cFS-GitHub/cfe/fsw/cfe-core/src/sb/cfe_sb_api.c:1433:16: error: ‘RouteId’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
         Status = CFE_SB_TransmitBufferFull(BufDscPtr, RouteId, MsgId);
                ^
/home/jhageman/cFS/cFS-GitHub/cfe/fsw/cfe-core/src/sb/cfe_sb_api.c: In function ‘CFE_SB_SendMsg’:
/home/jhageman/cFS/cFS-GitHub/cfe/fsw/cfe-core/src/sb/cfe_sb_api.c:1433:16: error: ‘RouteId’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
/home/jhageman/cFS/cFS-GitHub/cfe/fsw/cfe-core/src/sb/cfe_sb_api.c:1395:25: note: ‘RouteId’ was declared here
     CFE_SBR_RouteId_t   RouteId;
                         ^
/home/jhageman/cFS/cFS-GitHub/cfe/fsw/cfe-core/src/sb/cfe_sb_api.c: In function ‘CFE_SB_PassMsg’:
/home/jhageman/cFS/cFS-GitHub/cfe/fsw/cfe-core/src/sb/cfe_sb_api.c:1433:16: error: ‘RouteId’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
         Status = CFE_SB_TransmitBufferFull(BufDscPtr, RouteId, MsgId);
                ^
/home/jhageman/cFS/cFS-GitHub/cfe/fsw/cfe-core/src/sb/cfe_sb_api.c:1395:25: note: ‘RouteId’ was declared here
     CFE_SBR_RouteId_t   RouteId;
                         ^
/home/jhageman/cFS/cFS-GitHub/cfe/fsw/cfe-core/src/sb/cfe_sb_api.c: In function ‘CFE_SB_RcvMsg’:
/home/jhageman/cFS/cFS-GitHub/cfe/fsw/cfe-core/src/sb/cfe_sb_api.c:2045:43: error: ‘RcvStatus’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
                 CFE_EVS_SendEventWithAppID(CFE_SB_Q_RD_ERR_EID,CFE_EVS_EventType_ERROR,CFE_SB_Global.AppId,
                                           ^
/home/jhageman/cFS/cFS-GitHub/cfe/fsw/cfe-core/src/sb/cfe_sb_api.c:1823:28: note: ‘RcvStatus’ was declared here
     int32                  RcvStatus;
                            ^
/home/jhageman/cFS/cFS-GitHub/cfe/fsw/cfe-core/src/sb/cfe_sb_api.c: In function ‘CFE_SB_ReceiveBuffer’:
/home/jhageman/cFS/cFS-GitHub/cfe/fsw/cfe-core/src/sb/cfe_sb_api.c:2045:43: error: ‘RcvStatus’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
                 CFE_EVS_SendEventWithAppID(CFE_SB_Q_RD_ERR_EID,CFE_EVS_EventType_ERROR,CFE_SB_Global.AppId,
                                           ^

Describe the solution you'd like
Initialize variables where needed

Describe alternatives you've considered
None

Additional context
Compiler warnings, vs static analysis warnings reported in #1185

Requester Info
Jacob Hageman - NASA/GSFC

@skliper skliper added this to the 7.0.0 milestone Mar 1, 2021
@skliper
Copy link
Contributor Author

skliper commented Mar 1, 2021

GCC version 4.8.5 20150623 (Red Hat 4.8.5-44), vs CI which uses gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0.

@jphickey jphickey self-assigned this Mar 1, 2021
jphickey added a commit to jphickey/cFE that referenced this issue Mar 1, 2021
Corrects two false alarms about uninitialized vars and another
cast-align warning on the raspbian toolchain (gcc 4.9.3) or
other older versions of gcc (e.g. RHEL/CentOS 7).

- Promotes the CFE_SBR_INVALID_ROUTE_ID constant from the private
  cfe_sbr_priv.h header to the public cfe_sbr.h header (where the
  type itself is defined).
- Pre-Initialize local stack variables that store outputs from other
  functions (avoids false warning about use-before-init).
- Corrects an alignment warning on ARM.
@jphickey jphickey linked a pull request Mar 1, 2021 that will close this issue
jphickey added a commit to jphickey/cFE that referenced this issue Mar 1, 2021
In the event that CFE_SB_TransmitMsgValidate fails, make sure
all outputs are also written as safe/known (but invalid) values.

This is just in case the calling function does not check the
status response and uses the output value anyway (which would
be wrong, but this is just another layer of protection if
it does happen).
astrogeco added a commit that referenced this issue Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants