@@ -1700,29 +1700,28 @@ omemo_encrypt_file(FILE* in, FILE* out, off_t file_size, int* gcry_res)
17001700 return fragment ;
17011701}
17021702
1703- int
1704- _bytes_from_hex (const char * hex ,
1705- unsigned char * bytes , size_t * size )
1703+ void
1704+ _bytes_from_hex (const char * hex , size_t hex_size ,
1705+ unsigned char * bytes , size_t bytes_size )
17061706{
17071707 const unsigned char ht [] = {
17081708 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , // 01234567
17091709 0x08 , 0x09 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , // 89:;<=>?
17101710 0x00 , 0x0a , 0x0b , 0x0c , 0x0d , 0x0e , 0x0f , 0x00 , // @ABCDEFG
17111711 };
17121712 const size_t ht_size = sizeof (ht );
1713- size_t wr = 0 ;
1714- const char * h = hex ;
1715- unsigned char * out = bytes ;
17161713
17171714 unsigned char b0 ;
17181715 unsigned char b1 ;
17191716
1720- for (; * h && * (h + 1 ); h += 2 ) {
1721- b0 = ((unsigned char )* h & 0x1f ) ^ 0x10 ;
1722- b1 = ((unsigned char )* (h + 1 ) & 0x1f ) ^ 0x10 ;
1717+ memset (bytes , 0 , bytes_size );
1718+
1719+ for (int i = 0 ; (i < hex_size ) && (i / 2 < bytes_size ); i += 2 ) {
1720+ b0 = ((unsigned char )hex [i + 0 ] & 0x1f ) ^ 0x10 ;
1721+ b1 = ((unsigned char )hex [i + 1 ] & 0x1f ) ^ 0x10 ;
17231722
1724- if (wr < * size && b0 <= ht_size && b1 <= ht_size ) {
1725- bytes [wr ++ ] = (unsigned char )(ht [b0 ] << 4 ) | ht [b1 ];
1723+ if (b0 <= ht_size && b1 <= ht_size ) {
1724+ bytes [i / 2 ] = (unsigned char )(ht [b0 ] << 4 ) | ht [b1 ];
17261725 }
17271726 }
17281727}
0 commit comments