Fix error handling in hex_decode.

Problem found while refactoring usage in examples/turnserver/.

Bug: webrtc:6424
Change-Id: Ib1d54055c5914136b5bf165d48ab7d19520ff967
Reviewed-on: https://webrtc-review.googlesource.com/c/108302
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25412}
This commit is contained in:
Niels Möller
2018-10-29 12:58:48 +01:00
committed by Commit Bot
parent ef45669acf
commit 12048c7150
2 changed files with 4 additions and 3 deletions

View File

@ -60,9 +60,9 @@ char hex_encode(unsigned char val) {
bool hex_decode(char ch, unsigned char* val) {
if ((ch >= '0') && (ch <= '9')) {
*val = ch - '0';
} else if ((ch >= 'A') && (ch <= 'Z')) {
} else if ((ch >= 'A') && (ch <= 'F')) {
*val = (ch - 'A') + 10;
} else if ((ch >= 'a') && (ch <= 'z')) {
} else if ((ch >= 'a') && (ch <= 'f')) {
*val = (ch - 'a') + 10;
} else {
return false;

View File

@ -141,7 +141,8 @@ TEST_F(HexEncodeTest, TestDecodeTooShort) {
// Test that decoding non-hex data fails.
TEST_F(HexEncodeTest, TestDecodeBogusData) {
dec_res_ = hex_decode_with_delimiter(decoded_, sizeof(decoded_), "xyz", 3, 0);
dec_res_ =
hex_decode_with_delimiter(decoded_, sizeof(decoded_), "axyz", 4, 0);
ASSERT_EQ(0U, dec_res_);
}