Skip to content

Commit

Permalink
Merge pull request #73 from jphickey/fix-72-multitype-safety
Browse files Browse the repository at this point in the history
Fix #72, correct use of union type
  • Loading branch information
dzbaker committed Feb 16, 2023
2 parents f49a965 + bcdf8f1 commit 3c8a327
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions fsw/src/lc_watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,52 +851,52 @@ bool LC_GetSizedWPData(uint16 WatchIndex, const uint8 *WPDataPtr, uint32 *SizedD
switch (LC_OperData.WDTPtr[WatchIndex].DataType)
{
case LC_DATA_BYTE:
TempBuffer.Unsigned8 = *WPDataPtr;
ConvBuffer.Signed32 = TempBuffer.Signed8; /* Extend signed 8 bit value to 32 bits */
TempBuffer.Signed8 = *WPDataPtr;
*SizedDataPtr = TempBuffer.Signed8; /* Extend signed 8 bit value to 32 bits */
break;

case LC_DATA_UBYTE:
ConvBuffer.Unsigned32 = *WPDataPtr; /* Extend unsigned 8 bit value to 32 bits */
*SizedDataPtr = *WPDataPtr; /* Extend unsigned 8 bit value to 32 bits */
break;

case LC_DATA_WORD_BE:
ConvBuffer.Unsigned16 = LC_16BIT_BE_VAL;
LC_CopyBytesWithSwap(&TempBuffer, WPDataPtr, &ConvBuffer, sizeof(int16));
ConvBuffer.Signed32 = TempBuffer.Signed16; /* Extend signed 16 bit value to 32 bits */
*SizedDataPtr = TempBuffer.Signed16; /* Extend signed 16 bit value to 32 bits */
break;

case LC_DATA_WORD_LE:
ConvBuffer.Unsigned16 = LC_16BIT_LE_VAL;
LC_CopyBytesWithSwap(&TempBuffer, WPDataPtr, &ConvBuffer, sizeof(int16));
ConvBuffer.Signed32 = TempBuffer.Signed16; /* Extend signed 16 bit value to 32 bits */
*SizedDataPtr = TempBuffer.Signed16; /* Extend signed 16 bit value to 32 bits */
break;

case LC_DATA_UWORD_BE:
ConvBuffer.Unsigned16 = LC_16BIT_BE_VAL;
LC_CopyBytesWithSwap(&TempBuffer, WPDataPtr, &ConvBuffer, sizeof(uint16));
ConvBuffer.Unsigned32 = TempBuffer.Unsigned16; /* Extend unsigned 16 bit value to 32 bits */
*SizedDataPtr = TempBuffer.Unsigned16; /* Extend unsigned 16 bit value to 32 bits */
break;

case LC_DATA_UWORD_LE:
ConvBuffer.Unsigned16 = LC_16BIT_LE_VAL;
LC_CopyBytesWithSwap(&TempBuffer, WPDataPtr, &ConvBuffer, sizeof(uint16));
ConvBuffer.Unsigned32 = TempBuffer.Unsigned16; /* Extend unsigned 16 bit value to 32 bits */
*SizedDataPtr = TempBuffer.Unsigned16; /* Extend unsigned 16 bit value to 32 bits */
break;

case LC_DATA_DWORD_BE:
case LC_DATA_UDWORD_BE:
case LC_DATA_FLOAT_BE:
ConvBuffer.Unsigned32 = LC_32BIT_BE_VAL;
LC_CopyBytesWithSwap(&TempBuffer, WPDataPtr, &ConvBuffer, sizeof(uint32));
ConvBuffer.Unsigned32 = TempBuffer.Unsigned32; /* Straight copy - no extension (signed or unsigned) */
*SizedDataPtr = TempBuffer.Unsigned32; /* Straight copy - no extension (signed or unsigned) */
break;

case LC_DATA_DWORD_LE:
case LC_DATA_UDWORD_LE:
case LC_DATA_FLOAT_LE:
ConvBuffer.Unsigned32 = LC_32BIT_LE_VAL;
LC_CopyBytesWithSwap(&TempBuffer, WPDataPtr, &ConvBuffer, sizeof(uint32));
ConvBuffer.Unsigned32 = TempBuffer.Unsigned32; /* Straight copy - no extension (signed or unsigned) */
*SizedDataPtr = TempBuffer.Unsigned32; /* Straight copy - no extension (signed or unsigned) */
break;

default:
Expand All @@ -911,20 +911,15 @@ bool LC_GetSizedWPData(uint16 WatchIndex, const uint8 *WPDataPtr, uint32 *SizedD
LC_OperData.WRTPtr[WatchIndex].WatchResult = LC_WATCH_ERROR;
LC_OperData.WRTPtr[WatchIndex].CountdownToStale = 0;

Success = false;
Success = false;
*SizedDataPtr = 0;
break;

} /* end switch */

/*
** Set result value
*/
*SizedDataPtr = ConvBuffer.Unsigned32;

/*
** Return success flag
*/

return Success;
}

Expand Down

0 comments on commit 3c8a327

Please sign in to comment.