@@ -80,8 +80,7 @@ size_t sp_packet_serialize(const sp_packet_t *pkt, uint8_t *buf,
8080
8181 if (crc_present ) {
8282 /* compute CRC over secondary header and payload */
83- size_t crc_area_len =
84- (pkt -> ph .sec_hdr_flag ? pkt -> sec_hdr_len : 0 ) + pkt -> payload_len ;
83+ size_t crc_area_len = (pkt -> ph .sec_hdr_flag ? (size_t )pkt -> sec_hdr_len : (size_t )0 ) + (size_t )pkt -> payload_len ;
8584 uint16_t crc = sp_crc16_ccitt (& buf [6 ], crc_area_len );
8685 buf [off ++ ] = (uint8_t )((crc >> 8 ) & 0xFF );
8786 buf [off ++ ] = (uint8_t )(crc & 0xFF );
@@ -100,12 +99,12 @@ int sp_packet_parse(sp_packet_t *out, uint8_t *buf, size_t buf_len) {
10099 uint16_t second = ((uint16_t )buf [2 ] << 8 ) | buf [3 ];
101100 uint16_t length_field = ((uint16_t )buf [4 ] << 8 ) | buf [5 ];
102101
103- out -> ph .version = (first >> 13 ) & 0x7 ;
104- out -> ph .type = (first >> 12 ) & 0x1 ;
105- out -> ph .sec_hdr_flag = (first >> 11 ) & 0x1 ;
106- out -> ph .apid = first & 0x07FF ;
107- out -> ph .seq_flags = (second >> 14 ) & 0x3 ;
108- out -> ph .seq_count = second & 0x3FFF ;
102+ out -> ph .version = (unsigned )(( first >> 13 ) & 0x7 ) ;
103+ out -> ph .type = (unsigned )(( first >> 12 ) & 0x1 ) ;
104+ out -> ph .sec_hdr_flag = (unsigned )(( first >> 11 ) & 0x1 ) ;
105+ out -> ph .apid = ( unsigned short )( first & 0x07FF ) ;
106+ out -> ph .seq_flags = (unsigned )(( second >> 14 ) & 0x3 ) ;
107+ out -> ph .seq_count = ( unsigned short )( second & 0x3FFF ) ;
109108 out -> ph .packet_length = length_field ;
110109
111110 uint16_t total_len = (uint16_t )(length_field + 1 );
@@ -194,12 +193,12 @@ void sp_set_primary_header(sp_packet_t *pkt,
194193 uint8_t seq_flags ,
195194 uint16_t seq_count ) {
196195 if (!pkt ) return ;
197- pkt -> ph .version = version & 0x7 ;
198- pkt -> ph .type = type & 0x1 ;
199- pkt -> ph .sec_hdr_flag = sec_hdr_flag ? 1 : 0 ;
200- pkt -> ph .apid = apid & 0x07FF ;
201- pkt -> ph .seq_flags = seq_flags & 0x3 ;
202- pkt -> ph .seq_count = seq_count & 0x3FFF ;
196+ pkt -> ph .version = ( unsigned )( version & 0x7 ) ;
197+ pkt -> ph .type = ( unsigned )( type & 0x1 ) ;
198+ pkt -> ph .sec_hdr_flag = ( unsigned )( sec_hdr_flag ? 1 : 0 ) ;
199+ pkt -> ph .apid = ( unsigned short )( apid & 0x07FF ) ;
200+ pkt -> ph .seq_flags = ( unsigned )( seq_flags & 0x3 ) ;
201+ pkt -> ph .seq_count = ( unsigned short )( seq_count & 0x3FFF ) ;
203202}
204203
205204void sp_set_secondary_header (sp_packet_t * pkt , const uint8_t * sec_hdr , uint16_t sec_hdr_len ) {
0 commit comments