[RFC PATCH 5/6] object-name: use hexval
- From
brian m. carlson <sandals@crustytoothpaste.net>
- Date
- Jul 29, 2026, 23:32 UTC
- Message-ID
- <20260729233215.398654-6-sandals@crustytoothpaste.net>
- In-Reply-To
- <20260729233215.398654-1-sandals@crustytoothpaste.net>
We've open-coded a different implementation of parsing hex values here when we already have a perfectly good one in hexval. This implementation will almost certainly be slower because it isn't table-driven, unlike the other one, and since it's not constant time it has no other advantages either. To tidy things up and prepare for future work, switch to hexval in this case.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> --- object-name.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/object-name.c b/object-name.c index 83efba0ba6..d2d81b3511 100644 --- a/object-name.c +++ b/object-name.c @@ -236,17 +236,10 @@ static int parse_oid_prefix(const char *name, int len, { for (int i = 0; i < len; i++) { unsigned char c = name[i]; - unsigned char val; - if (c >= '0' && c <= '9') { - val = c - '0'; - } else if (c >= 'a' && c <= 'f') { - val = c - 'a' + 10; - } else if (c >= 'A' && c <='F') { - val = c - 'A' + 10; - c -= 'A' - 'a'; - } else { + int val = hexval(c, HEX_KIND_OID); + + if (val < 0) return -1; - } if (hex_out) hex_out[i] = c;