aboutsummaryrefslogtreecommitdiff
path: root/pkt-line.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-09-12 15:34:36 -0700
committerJunio C Hamano <gitster@pobox.com>2016-09-12 15:34:36 -0700
commite4ec05ed93bede22b0d79ab58997f0fc170929e9 (patch)
treef2e445694b466952e89b616977832a641432db9b /pkt-line.c
parent27853a85edce65afd73c8bb0ca7adf0a4468def3 (diff)
parentd23309733a5b2a9e1adc304ee50c5a5ed7a087c2 (diff)
downloadgit-e4ec05ed93bede22b0d79ab58997f0fc170929e9.tar.gz
git-e4ec05ed93bede22b0d79ab58997f0fc170929e9.tar.xz
Merge branch 'rs/hex2chr'
* rs/hex2chr: introduce hex2chr() for converting two hexadecimal digits to a character
Diffstat (limited to 'pkt-line.c')
-rw-r--r--pkt-line.c23
1 files changed, 2 insertions, 21 deletions
diff --git a/pkt-line.c b/pkt-line.c
index 62fdb3707..30489c60b 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -172,27 +172,8 @@ static int get_packet_data(int fd, char **src_buf, size_t *src_size,
static int packet_length(const char *linelen)
{
- int n;
- int len = 0;
-
- for (n = 0; n < 4; n++) {
- unsigned char c = linelen[n];
- len <<= 4;
- if (c >= '0' && c <= '9') {
- len += c - '0';
- continue;
- }
- if (c >= 'a' && c <= 'f') {
- len += c - 'a' + 10;
- continue;
- }
- if (c >= 'A' && c <= 'F') {
- len += c - 'A' + 10;
- continue;
- }
- return -1;
- }
- return len;
+ int val = hex2chr(linelen);
+ return (val < 0) ? val : (val << 8) | hex2chr(linelen + 2);
}
int packet_read(int fd, char **src_buf, size_t *src_len,