diff options
author | Niels Thykier <nthykier@debian.org> | 2015-12-27 03:16:55 +0100 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2015-12-27 03:16:55 +0100 |
commit | fc8f1c22523ffc54f5440e19663aa1009b4126ca (patch) | |
tree | 3f1d5bd93c64d5021bc6f3d232d1e8a9a53d10a2 | |
parent | 0e0bff781d58a2b02c5b812fc9acd929a07105a9 (diff) |
Hex2Digit: Do not use isxdigit()
We directly check if we are a hex digit in HexDigit, so use that
information.
[jak@debian.org: Commit message wording]
-rw-r--r-- | apt-pkg/contrib/strutl.cc | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index de049602f..457bd73a2 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1106,7 +1106,7 @@ static int HexDigit(int c) return c - 'a' + 10; if (c >= 'A' && c <= 'F') return c - 'A' + 10; - return 0; + return -1; } /*}}}*/ // Hex2Num - Convert a long hex number into a buffer /*{{{*/ @@ -1121,11 +1121,16 @@ bool Hex2Num(const string &Str,unsigned char *Num,unsigned int Length) int J = 0; for (string::const_iterator I = Str.begin(); I != Str.end();J++, I += 2) { - if (isxdigit(*I) == 0 || isxdigit(I[1]) == 0) + int first_half = HexDigit(I[0]); + int second_half; + if (first_half < 0) return false; - Num[J] = HexDigit(I[0]) << 4; - Num[J] += HexDigit(I[1]); + second_half = HexDigit(I[1]); + if (second_half < 0) + return false; + Num[J] = first_half << 4; + Num[J] += second_half; } return true; |