Skip to content

Commit c661fd4

Browse files
committed
hex: fix test valgrind error caused by sscanf
1 parent 28880ea commit c661fd4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

extras/test/src/hex/test_hex.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ SCENARIO( "HEX encoding test" ) {
1818
for(i = 0; i <= 0xffff; ++i){
1919
/* encode to hex string using our implementation */
2020
const unsigned char org[2] = {(unsigned char)(i>>8), (unsigned char)i};
21-
char hex[5];
21+
char hex[5] = {0,0,0,0,0};
2222
chex_encode(hex, sizeof(hex), org, sizeof(org));
2323

2424
/* decode from hex string using a function from the standard library */
25-
unsigned char bin[2];
25+
unsigned char bin[2] = {0,0};
2626
int n = sscanf(hex, "%02hhx%02hhx", bin, bin+1);
2727
REQUIRE(n == sizeof(bin));
2828

@@ -37,7 +37,7 @@ SCENARIO( "HEX decoding test" ) {
3737
unsigned i;
3838
for(i = 0; i <= 0xffff; ++i){
3939
/* encode to hex string using a function from the standard library */
40-
char hex[5];
40+
char hex[5] = {0,0,0,0,0};
4141
snprintf(hex, sizeof(hex), "%02hhX%02hhx", (unsigned char)(i>>8), (unsigned char)i);
4242

4343
/* decode from hex string using our implementation */

0 commit comments

Comments
 (0)