Skip to content

Commit

Permalink
Fix #1189, fix compiler warnings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jphickey committed Mar 1, 2021
1 parent 0ab0a48 commit 54adb9f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
7 changes: 7 additions & 0 deletions fsw/cfe-core/src/inc/private/cfe_sbr.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
#include "cfe_msg_typedefs.h"
#include "cfe_platform_cfg.h"

/*
* Macro Definitions
*/

/** \brief Invalid route id */
#define CFE_SBR_INVALID_ROUTE_ID ((CFE_SBR_RouteId_t) {.RouteId = 0})

/******************************************************************************
* Type Definitions
*/
Expand Down
2 changes: 2 additions & 0 deletions fsw/cfe-core/src/sb/cfe_sb_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,7 @@ int32 CFE_SB_TransmitMsg(CFE_MSG_Message_t *MsgPtr, bool IncrementSequenceCount

PendingEventID = 0;
BufDscPtr = NULL;
RouteId = CFE_SBR_INVALID_ROUTE_ID;

Status = CFE_SB_TransmitMsgValidate(MsgPtr, &MsgId, &Size, &RouteId);

Expand Down Expand Up @@ -1886,6 +1887,7 @@ int32 CFE_SB_ReceiveBuffer(CFE_SB_Buffer_t **BufPtr,
BufDscPtr = NULL;
DestPtr = NULL;
BufDscSize = 0;
RcvStatus = OS_SUCCESS;

/*
* Check input args and see if any are bad, which require
Expand Down
18 changes: 6 additions & 12 deletions fsw/cfe-core/src/sb/cfe_sb_priv.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,15 +536,7 @@ void CFE_SB_RemoveDestNode(CFE_SBR_RouteId_t RouteId, CFE_SB_DestinationD_t *Nod
int32 CFE_SB_ZeroCopyReleaseAppId(CFE_ES_AppId_t AppId)
{
CFE_SB_BufferLink_t *NextLink;

/* Using a union type permits promotion of CFE_SB_BufferLink_t* to CFE_SB_BufferD_t*
* without violating aliasing rules or alignment rules. Note that the first element
* of CFE_SB_BufferD_t is a CFE_SB_BufferLink_t, which makes this possible. */
union LocalBufDesc
{
CFE_SB_BufferLink_t As_Link;
CFE_SB_BufferD_t As_Dsc;
} *BufPtr;
CFE_SB_BufferD_t *DscPtr;

/*
* First go through the "ZeroCopy" tracking list and find all nodes
Expand All @@ -560,16 +552,18 @@ int32 CFE_SB_ZeroCopyReleaseAppId(CFE_ES_AppId_t AppId)
while(!CFE_SB_TrackingListIsEnd(&CFE_SB_Global.ZeroCopyList, NextLink))
{
/* Get buffer descriptor pointer */
BufPtr = (union LocalBufDesc*)NextLink;
/* NOTE: casting via void* here rather than CFE_SB_BufferD_t* avoids a false
* alignment warning on platforms with strict alignment requirements */
DscPtr = (void *)NextLink;

/* Read the next link now in case this node gets moved */
NextLink = CFE_SB_TrackingListGetNext(NextLink);

/* Check if it is a zero-copy buffer owned by this app */
if (CFE_RESOURCEID_TEST_EQUAL(BufPtr->As_Dsc.AppId, AppId))
if (CFE_RESOURCEID_TEST_EQUAL(DscPtr->AppId, AppId))
{
/* If so, decrement the use count as the app has now gone away */
CFE_SB_DecrBufUseCnt(&BufPtr->As_Dsc);
CFE_SB_DecrBufUseCnt(DscPtr);
}
}

Expand Down
6 changes: 0 additions & 6 deletions modules/sbr/private_inc/cfe_sbr_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@
*/
#include "private/cfe_sbr.h"

/*
* Macro Definitions
*/

/** \brief Invalid route id */
#define CFE_SBR_INVALID_ROUTE_ID ((CFE_SBR_RouteId_t) {.RouteId = 0})

/******************************************************************************
* Function prototypes
Expand Down

0 comments on commit 54adb9f

Please sign in to comment.