@@ -233,7 +233,7 @@ void msg_process(char type, uint16_t msg_id, const pb_field_t *fields, uint8_t *
233233 }
234234}
235235
236- void msg_read_common (char type , const uint8_t * buf , int len )
236+ void msg_read_common (char type , const uint8_t * buf , uint32_t len )
237237{
238238 static char read_state = READSTATE_IDLE ;
239239 static CONFIDENTIAL uint8_t msg_in [MSG_IN_SIZE ];
@@ -271,8 +271,12 @@ void msg_read_common(char type, const uint8_t *buf, int len)
271271 read_state = READSTATE_IDLE ;
272272 return ;
273273 }
274- memcpy (msg_in + msg_pos , buf + 1 , len - 1 );
275- msg_pos += len - 1 ;
274+ /* raw data starts at buf + 1 with len - 1 bytes */
275+ buf ++ ;
276+ len = MIN (len - 1 , MSG_IN_SIZE - msg_pos );
277+
278+ memcpy (msg_in + msg_pos , buf , len );
279+ msg_pos += len ;
276280 }
277281
278282 if (msg_pos >= msg_size ) {
@@ -329,8 +333,7 @@ void msg_read_tiny(const uint8_t *buf, int len)
329333 }
330334
331335 const pb_field_t * fields = 0 ;
332- // upstream nanopb is missing const qualifier, so we have to cast :-/
333- pb_istream_t stream = pb_istream_from_buffer ((uint8_t * )buf + 9 , msg_size );
336+ pb_istream_t stream = pb_istream_from_buffer (buf + 9 , msg_size );
334337
335338 switch (msg_id ) {
336339 case MessageType_MessageType_PinMatrixAck :
0 commit comments