Skip to content

Commit

Permalink
AP_Common: char_to_hex returns 0 on invalid char
Browse files Browse the repository at this point in the history
  • Loading branch information
rmackay9 committed Jul 4, 2024
1 parent 6217643 commit 2da4b0d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions libraries/AP_Common/AP_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ size_t strncpy_noterm(char *dest, const char *src, size_t n)
*/
int16_t char_to_hex(char a)
{
if (a >= 'A' && a <= 'F')
if (a >= 'A' && a <= 'F') {
return a - 'A' + 10;
else if (a >= 'a' && a <= 'f')
} else if (a >= 'a' && a <= 'f') {
return a - 'a' + 10;
else
} else if (a >= '0' && a <= '9') {
return a - '0';
}
return 0;
}

0 comments on commit 2da4b0d

Please sign in to comment.