зеркало из https://github.com/microsoft/git.git
Merge branch 'rs/packet-length-simplify'
Code simplification. * rs/packet-length-simplify: pkt-line: add size parameter to packet_length()
This commit is contained in:
Коммит
377d1ca423
12
pkt-line.c
12
pkt-line.c
|
@ -373,10 +373,14 @@ static int get_packet_data(int fd, char **src_buf, size_t *src_size,
|
|||
return ret;
|
||||
}
|
||||
|
||||
int packet_length(const char lenbuf_hex[4])
|
||||
int packet_length(const char lenbuf_hex[4], size_t size)
|
||||
{
|
||||
int val = hex2chr(lenbuf_hex);
|
||||
return (val < 0) ? val : (val << 8) | hex2chr(lenbuf_hex + 2);
|
||||
if (size < 4)
|
||||
BUG("buffer too small");
|
||||
return hexval(lenbuf_hex[0]) << 12 |
|
||||
hexval(lenbuf_hex[1]) << 8 |
|
||||
hexval(lenbuf_hex[2]) << 4 |
|
||||
hexval(lenbuf_hex[3]);
|
||||
}
|
||||
|
||||
static char *find_packfile_uri_path(const char *buffer)
|
||||
|
@ -419,7 +423,7 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
|
|||
return PACKET_READ_EOF;
|
||||
}
|
||||
|
||||
len = packet_length(linelen);
|
||||
len = packet_length(linelen, sizeof(linelen));
|
||||
|
||||
if (len < 0) {
|
||||
if (options & PACKET_READ_GENTLE_ON_READ_ERROR)
|
||||
|
|
|
@ -94,7 +94,7 @@ int packet_read(int fd, char *buffer, unsigned size, int options);
|
|||
* If lenbuf_hex contains non-hex characters, return -1. Otherwise, return the
|
||||
* numeric value of the length header.
|
||||
*/
|
||||
int packet_length(const char lenbuf_hex[4]);
|
||||
int packet_length(const char lenbuf_hex[4], size_t size);
|
||||
|
||||
/*
|
||||
* Read a packetized line into a buffer like the 'packet_read()' function but
|
||||
|
|
|
@ -763,7 +763,8 @@ static void check_pktline(struct check_pktline_state *state, const char *ptr, si
|
|||
size -= digits_remaining;
|
||||
|
||||
if (state->len_filled == 4) {
|
||||
state->remaining = packet_length(state->len_buf);
|
||||
state->remaining = packet_length(state->len_buf,
|
||||
sizeof(state->len_buf));
|
||||
if (state->remaining < 0) {
|
||||
die(_("remote-curl: bad line length character: %.4s"), state->len_buf);
|
||||
} else if (state->remaining == 2) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче