Skip to content

Commit

Permalink
fix GetParity and SetParity uint8_t overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
KaDw authored and Karol Dworakowski committed Sep 10, 2019
1 parent 180c8de commit 3c1dca8
Showing 1 changed file with 4 additions and 4 deletions.
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

0 comments on commit 3c1dca8

Please sign in to comment.