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

fix GetParity and SetParity uint8_t overflow #786

Merged
merged 1 commit into from
Sep 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/apps/LoRaMac/common/LmHandler/packages/FragDecoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static void GetRow( uint8_t *dst, uint8_t *src, uint16_t row, uint16_t size );
*
* \retval parity Parity value at the given index
*/
static uint8_t GetParity( uint8_t index, uint8_t *matrixRow );
static uint8_t GetParity( uint16_t index, uint8_t *matrixRow );

/*!
* \brief Sets the parity value on the given row of the parity matrix
Expand All @@ -127,7 +127,7 @@ static uint8_t GetParity( uint8_t index, uint8_t *matrixRow );
* \param [IN/OUT] matrixRow Pointer to the parity matrix.
* \param [IN] parity The parity value to be set in the parity matrix
*/
static void SetParity( uint8_t index, uint8_t *matrixRow, uint8_t parity );
static void SetParity( uint16_t index, uint8_t *matrixRow, uint8_t parity );

/*!
* \brief Check if the provided value is a power of 2
Expand Down Expand Up @@ -518,15 +518,15 @@ static void GetRow( uint8_t *dst, uint8_t *src, uint16_t row, uint16_t size )
}
#endif

static uint8_t GetParity( uint8_t index, uint8_t *matrixRow )
static uint8_t GetParity( uint16_t index, uint8_t *matrixRow )
{
uint8_t parity;
parity = matrixRow[index >> 3];
parity = ( parity >> ( 7 - ( index % 8 ) ) ) & 0x01;
return parity;
}

static void SetParity( uint8_t index, uint8_t *matrixRow, uint8_t parity )
static void SetParity( uint16_t index, uint8_t *matrixRow, uint8_t parity )
{
uint8_t mask = 0xFF - ( 1 << ( 7 - ( index % 8 ) ) );
parity = parity << ( 7 - ( index % 8 ) );
Expand Down