Skip to content

Commit

Permalink
Fix nasa#663, Scrub datatypes across SB
Browse files Browse the repository at this point in the history
Fix all use of uint32 for sizes, replace with size_t
Scrub all other types to make sure use is consistent,
using proper typedef whenever available.
  • Loading branch information
jphickey committed Nov 18, 2020
1 parent bb6124f commit 97d9fd5
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 68 deletions.
34 changes: 8 additions & 26 deletions fsw/cfe-core/src/inc/cfe_sb.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,6 @@
#define CFE_CLR(i,x) ((i) &= ~CFE_BIT(x)) /**< \brief Clears bit x of i */
#define CFE_TST(i,x) (((i) & CFE_BIT(x)) != 0)/**< \brief true(non zero) if bit x of i is set */

/**
* \brief Set memory address within SB Message
*
* Macro that should be used to set memory addresses within software bus messages.
* For now this does a straight copy, but in a future revision this may translate the
* raw memory address into a "safe" integer value. This is particularly important if
* the message is to be sent off this CPU.
*/
#define CFE_SB_SET_MEMADDR(msgdst,src) msgdst = (cpuaddr)src

/**
* \brief Get memory address from SB Message
*
* Macro that should be used to get memory addresses from software bus messages.
* This is the inverse operation of CFE_SB_SET_MEMADDR.
*/
#define CFE_SB_GET_MEMADDR(msgsrc) (cpuaddr)msgsrc

/*
** Pipe option bit fields.
*/
Expand Down Expand Up @@ -671,7 +653,7 @@ CFE_Status_t CFE_SB_RcvMsg(CFE_SB_MsgPtr_t *BufPtr, CFE_SB_PipeId_t PipeId, int
**
** \sa #CFE_SB_ZeroCopyReleasePtr, #CFE_SB_ZeroCopySend
**/
CFE_SB_Msg_t *CFE_SB_ZeroCopyGetPtr(uint16 MsgSize,
CFE_SB_Msg_t *CFE_SB_ZeroCopyGetPtr(size_t MsgSize,
CFE_SB_ZeroCopyHandle_t *BufferHandle);

/*****************************************************************************/
Expand Down Expand Up @@ -820,7 +802,7 @@ CFE_Status_t CFE_SB_ZeroCopyPass(CFE_SB_Msg_t *MsgPtr, CFE_SB_ZeroCopyHandle_t B
**/
void CFE_SB_InitMsg(void *MsgPtr,
CFE_SB_MsgId_t MsgId,
uint16 Length,
size_t Length,
bool Clear );

/*****************************************************************************/
Expand Down Expand Up @@ -868,7 +850,7 @@ void CFE_SB_SetMsgId(CFE_SB_MsgPtr_t MsgPtr,
** \sa #CFE_SB_SetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_SetTotalMsgLength,
** #CFE_SB_SetMsgTime, #CFE_SB_TimeStampMsg, #CFE_SB_SetCmdCode, #CFE_SB_InitMsg
**/
void CFE_SB_SetUserDataLength(CFE_SB_MsgPtr_t MsgPtr,uint16 DataLength);
void CFE_SB_SetUserDataLength(CFE_SB_MsgPtr_t MsgPtr,size_t DataLength);

/*****************************************************************************/
/**
Expand All @@ -893,7 +875,7 @@ void CFE_SB_SetUserDataLength(CFE_SB_MsgPtr_t MsgPtr,uint16 DataLength);
** \sa #CFE_SB_SetMsgId, #CFE_SB_SetUserDataLength, #CFE_SB_GetTotalMsgLength,
** #CFE_SB_SetMsgTime, #CFE_SB_TimeStampMsg, #CFE_SB_SetCmdCode, #CFE_SB_InitMsg
**/
void CFE_SB_SetTotalMsgLength(CFE_SB_MsgPtr_t MsgPtr,uint16 TotalLength);
void CFE_SB_SetTotalMsgLength(CFE_SB_MsgPtr_t MsgPtr,size_t TotalLength);

/*****************************************************************************/
/**
Expand Down Expand Up @@ -1007,7 +989,7 @@ CFE_Status_t CFE_SB_SetCmdCode(CFE_SB_MsgPtr_t MsgPtr, uint16 CmdCode);
** \return Number of characters copied or error code, see \ref CFEReturnCodes
**
*/
int32 CFE_SB_MessageStringSet(char *DestStringPtr, const char *SourceStringPtr, uint32 DestMaxSize, uint32 SourceMaxSize);
int32 CFE_SB_MessageStringSet(char *DestStringPtr, const char *SourceStringPtr, size_t DestMaxSize, size_t SourceMaxSize);
/**@}*/

/** @defgroup CFEAPIGetMessage cFE Getting Message Characteristics APIs
Expand Down Expand Up @@ -1073,7 +1055,7 @@ CFE_SB_MsgId_t CFE_SB_GetMsgId(const CFE_SB_Msg_t *MsgPtr);
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_SetUserDataLength, #CFE_SB_GetTotalMsgLength,
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
**/
uint16 CFE_SB_GetUserDataLength(const CFE_SB_Msg_t *MsgPtr);
size_t CFE_SB_GetUserDataLength(const CFE_SB_Msg_t *MsgPtr);

/*****************************************************************************/
/**
Expand All @@ -1094,7 +1076,7 @@ uint16 CFE_SB_GetUserDataLength(const CFE_SB_Msg_t *MsgPtr);
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_SetTotalMsgLength,
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
**/
uint16 CFE_SB_GetTotalMsgLength(const CFE_SB_Msg_t *MsgPtr);
size_t CFE_SB_GetTotalMsgLength(const CFE_SB_Msg_t *MsgPtr);

/*****************************************************************************/
/**
Expand Down Expand Up @@ -1182,7 +1164,7 @@ CFE_TIME_SysTime_t CFE_SB_GetMsgTime(CFE_SB_MsgPtr_t MsgPtr);
** \return Number of characters copied or error code, see \ref CFEReturnCodes
**
*/
int32 CFE_SB_MessageStringGet(char *DestStringPtr, const char *SourceStringPtr, const char *DefaultString, uint32 DestMaxSize, uint32 SourceMaxSize);
int32 CFE_SB_MessageStringGet(char *DestStringPtr, const char *SourceStringPtr, const char *DefaultString, size_t DestMaxSize, size_t SourceMaxSize);
/**@}*/

/** @defgroup CFEAPISBChecksum cFE Checksum Control APIs
Expand Down
8 changes: 4 additions & 4 deletions fsw/cfe-core/src/sb/cfe_sb_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ int32 CFE_SB_SendMsgFull(CFE_SB_Msg_t *MsgPtr,
CFE_SB_PipeD_t *PipeDscPtr;
CFE_SBR_RouteId_t RouteId;
CFE_SB_BufferD_t *BufDscPtr;
uint16 TotalMsgSize;
size_t TotalMsgSize;
CFE_ES_ResourceID_t AppId;
CFE_ES_ResourceID_t TskId;
uint32 i;
Expand Down Expand Up @@ -1294,7 +1294,7 @@ int32 CFE_SB_SendMsgFull(CFE_SB_Msg_t *MsgPtr,
/* Copy the packet into the SB memory space */
if (CopyMode != CFE_SB_SEND_ZEROCOPY){
/* Copy the packet into the SB memory space */
memcpy( BufDscPtr->Buffer, MsgPtr, (uint16)TotalMsgSize );
memcpy( BufDscPtr->Buffer, MsgPtr, TotalMsgSize );
}

/* For Tlm packets, increment the seq count if requested */
Expand Down Expand Up @@ -1583,7 +1583,7 @@ int32 CFE_SB_RcvMsg(CFE_SB_MsgPtr_t *BufPtr,
/*
* Function: CFE_SB_ZeroCopyGetPtr - See API and header file for details
*/
CFE_SB_Msg_t *CFE_SB_ZeroCopyGetPtr(uint16 MsgSize,
CFE_SB_Msg_t *CFE_SB_ZeroCopyGetPtr(size_t MsgSize,
CFE_SB_ZeroCopyHandle_t *BufferHandle)
{
int32 stat1;
Expand Down Expand Up @@ -1835,7 +1835,7 @@ int32 CFE_SB_ReadQueue (CFE_SB_PipeD_t *PipeDscPtr,
CFE_SB_BufferD_t **Message)
{
int32 Status,TimeOut;
uint32 Nbytes;
size_t Nbytes;
char FullName[(OS_MAX_API_NAME * 2)];
char PipeName[OS_MAX_API_NAME] = {'\0'};

Expand Down
2 changes: 1 addition & 1 deletion fsw/cfe-core/src/sb/cfe_sb_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
** could not be allocated.
*/

CFE_SB_BufferD_t * CFE_SB_GetBufferFromPool(CFE_SB_MsgId_t MsgId, uint16 Size) {
CFE_SB_BufferD_t * CFE_SB_GetBufferFromPool(CFE_SB_MsgId_t MsgId, size_t Size) {
int32 stat1;
uint8 *address = NULL;
CFE_SB_BufferD_t *bd = NULL;
Expand Down
2 changes: 1 addition & 1 deletion fsw/cfe-core/src/sb/cfe_sb_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
** External Declarations
*/

const CFE_ES_MemOffset_t CFE_SB_MemPoolDefSize[CFE_PLATFORM_ES_POOL_MAX_BUCKETS] =
const size_t CFE_SB_MemPoolDefSize[CFE_PLATFORM_ES_POOL_MAX_BUCKETS] =
{
CFE_PLATFORM_SB_MAX_BLOCK_SIZE,
CFE_PLATFORM_SB_MEM_BLOCK_SIZE_16,
Expand Down
8 changes: 4 additions & 4 deletions fsw/cfe-core/src/sb/cfe_sb_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
typedef struct {
CFE_SB_MsgId_t MsgId;
uint16 UseCount;
uint32 Size;
size_t Size;
void *Buffer;
} CFE_SB_BufferD_t;

Expand All @@ -133,7 +133,7 @@ typedef struct {

typedef struct {
CFE_ES_ResourceID_t AppID;
uint32 Size;
size_t Size;
void *Buffer;
void *Next;
void *Prev;
Expand Down Expand Up @@ -249,7 +249,7 @@ void CFE_SB_ProcessCmdPipePkt(void);
void CFE_SB_ResetCounters(void);
void CFE_SB_SetMsgSeqCnt(CFE_SB_MsgPtr_t MsgPtr,uint32 Count);
char *CFE_SB_GetAppTskName(CFE_ES_ResourceID_t TaskId, char* FullName);
CFE_SB_BufferD_t *CFE_SB_GetBufferFromPool(CFE_SB_MsgId_t MsgId, uint16 Size);
CFE_SB_BufferD_t *CFE_SB_GetBufferFromPool(CFE_SB_MsgId_t MsgId, size_t Size);
CFE_SB_BufferD_t *CFE_SB_GetBufferFromCaller(CFE_SB_MsgId_t MsgId, void *Address);
CFE_SB_PipeD_t *CFE_SB_GetPipePtr(CFE_SB_PipeId_t PipeId);
CFE_SB_PipeId_t CFE_SB_GetAvailPipeIdx(void);
Expand Down Expand Up @@ -360,7 +360,7 @@ CFE_SB_DestinationD_t *CFE_SB_GetDestPtr(CFE_SBR_RouteId_t RouteId, CFE_SB_PipeI
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_GetTotalMsgLength,
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
**/
uint16 CFE_SB_MsgHdrSize(const CFE_SB_Msg_t *MsgPtr);
size_t CFE_SB_MsgHdrSize(const CFE_SB_Msg_t *MsgPtr);


/*
Expand Down
4 changes: 2 additions & 2 deletions fsw/cfe-core/src/sb/cfe_sb_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ int32 CFE_SB_AppInit(void){
** Return:
** true if length is acceptable
*/
bool CFE_SB_VerifyCmdLength(CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength)
bool CFE_SB_VerifyCmdLength(CFE_SB_MsgPtr_t Msg, size_t ExpectedLength)
{
bool result = true;
uint16 ActualLength = CFE_SB_GetTotalMsgLength(Msg);
size_t ActualLength = CFE_SB_GetTotalMsgLength(Msg);

/*
** Verify the command packet length
Expand Down
33 changes: 16 additions & 17 deletions fsw/cfe-core/src/sb/cfe_sb_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*/
void CFE_SB_InitMsg(void *MsgPtr,
CFE_SB_MsgId_t MsgId,
uint16 Length,
size_t Length,
bool Clear )
{

Expand All @@ -67,10 +67,9 @@ void CFE_SB_InitMsg(void *MsgPtr,
** Return:
** Size of Message Header.
*/
uint16 CFE_SB_MsgHdrSize(const CFE_SB_Msg_t *MsgPtr)
size_t CFE_SB_MsgHdrSize(const CFE_SB_Msg_t *MsgPtr)
{

uint16 size = 0;
size_t size = 0;
bool hassechdr = false;
CFE_MSG_Type_t type = CFE_MSG_Type_Invalid;

Expand Down Expand Up @@ -103,7 +102,7 @@ uint16 CFE_SB_MsgHdrSize(const CFE_SB_Msg_t *MsgPtr)
void *CFE_SB_GetUserData(CFE_SB_MsgPtr_t MsgPtr)
{
uint8 *BytePtr;
uint16 HdrSize;
size_t HdrSize;

BytePtr = (uint8 *)MsgPtr;
HdrSize = CFE_SB_MsgHdrSize(MsgPtr);
Expand All @@ -115,24 +114,25 @@ void *CFE_SB_GetUserData(CFE_SB_MsgPtr_t MsgPtr)
/*
* Function: CFE_SB_GetUserDataLength - See API and header file for details
*/
uint16 CFE_SB_GetUserDataLength(const CFE_SB_Msg_t *MsgPtr)
size_t CFE_SB_GetUserDataLength(const CFE_SB_Msg_t *MsgPtr)
{
uint32 TotalMsgSize;
uint16 HdrSize;
CFE_MSG_Size_t TotalMsgSize;
size_t HdrSize;

CFE_MSG_GetSize(MsgPtr, &TotalMsgSize);
HdrSize = CFE_SB_MsgHdrSize(MsgPtr);

return (TotalMsgSize - HdrSize);
return TotalMsgSize - HdrSize;
}/* end CFE_SB_GetUserDataLength */


/*
* Function: CFE_SB_SetUserDataLength - See API and header file for details
*/
void CFE_SB_SetUserDataLength(CFE_SB_MsgPtr_t MsgPtr, uint16 DataLength)
void CFE_SB_SetUserDataLength(CFE_SB_MsgPtr_t MsgPtr, size_t DataLength)
{
uint32 TotalMsgSize, HdrSize;
CFE_MSG_Size_t TotalMsgSize;
size_t HdrSize;

HdrSize = CFE_SB_MsgHdrSize(MsgPtr);
TotalMsgSize = HdrSize + DataLength;
Expand All @@ -144,23 +144,22 @@ void CFE_SB_SetUserDataLength(CFE_SB_MsgPtr_t MsgPtr, uint16 DataLength)
/*
* Function: CFE_SB_GetTotalMsgLength - See API and header file for details
*/
uint16 CFE_SB_GetTotalMsgLength(const CFE_SB_Msg_t *MsgPtr)
size_t CFE_SB_GetTotalMsgLength(const CFE_SB_Msg_t *MsgPtr)
{

CFE_MSG_Size_t size;

CFE_MSG_GetSize(MsgPtr, &size);

/* Known bug that this API can't return maximum ccsds size */
return (uint16)size;
return size;

}/* end CFE_SB_GetTotalMsgLength */


/*
* Function: CFE_SB_SetTotalMsgLength - See API and header file for details
*/
void CFE_SB_SetTotalMsgLength(CFE_SB_MsgPtr_t MsgPtr,uint16 TotalLength)
void CFE_SB_SetTotalMsgLength(CFE_SB_MsgPtr_t MsgPtr,size_t TotalLength)
{

CFE_MSG_SetSize(MsgPtr, TotalLength);
Expand Down Expand Up @@ -279,7 +278,7 @@ bool CFE_SB_ValidateChecksum(CFE_SB_MsgPtr_t MsgPtr)
/*
* Function: CFE_SB_MessageStringGet - See API and header file for details
*/
int32 CFE_SB_MessageStringGet(char *DestStringPtr, const char *SourceStringPtr, const char *DefaultString, uint32 DestMaxSize, uint32 SourceMaxSize)
int32 CFE_SB_MessageStringGet(char *DestStringPtr, const char *SourceStringPtr, const char *DefaultString, size_t DestMaxSize, size_t SourceMaxSize)
{
int32 Result;

Expand Down Expand Up @@ -331,7 +330,7 @@ int32 CFE_SB_MessageStringGet(char *DestStringPtr, const char *SourceStringPtr,
/*
* Function: CFE_SB_MessageStringSet - See API and header file for details
*/
int32 CFE_SB_MessageStringSet(char *DestStringPtr, const char *SourceStringPtr, uint32 DestMaxSize, uint32 SourceMaxSize)
int32 CFE_SB_MessageStringSet(char *DestStringPtr, const char *SourceStringPtr, size_t DestMaxSize, size_t SourceMaxSize)
{
int32 Result;

Expand Down
Loading

0 comments on commit 97d9fd5

Please sign in to comment.