Commit 05816a98 by Edward Thomson

netops: use GIT_ASSERT

parent ea7c807a
......@@ -61,18 +61,20 @@ void gitno_buffer_setup_fromstream(git_stream *st, gitno_buffer *buf, char *data
}
/* Consume up to ptr and move the rest of the buffer to the beginning */
void gitno_consume(gitno_buffer *buf, const char *ptr)
int gitno_consume(gitno_buffer *buf, const char *ptr)
{
size_t consumed;
assert(ptr - buf->data >= 0);
assert(ptr - buf->data <= (int) buf->len);
GIT_ASSERT(ptr - buf->data >= 0);
GIT_ASSERT(ptr - buf->data <= (int) buf->len);
consumed = ptr - buf->data;
memmove(buf->data, ptr, buf->offset - consumed);
memset(buf->data + buf->offset, 0x0, buf->len - buf->offset);
buf->offset -= consumed;
return 0;
}
/* Consume const bytes and move the rest of the buffer to the beginning */
......
......@@ -62,7 +62,7 @@ void gitno_buffer_setup_fromstream(git_stream *st, gitno_buffer *buf, char *data
void gitno_buffer_setup_callback(gitno_buffer *buf, char *data, size_t len, int (*recv)(gitno_buffer *buf), void *cb_data);
int gitno_recv(gitno_buffer *buf);
void gitno_consume(gitno_buffer *buf, const char *ptr);
int gitno_consume(gitno_buffer *buf, const char *ptr);
void gitno_consume_n(gitno_buffer *buf, size_t cons);
#endif
......@@ -64,7 +64,9 @@ int git_smart__store_refs(transport_smart *t, int flushes)
continue;
}
gitno_consume(buf, line_end);
if (gitno_consume(buf, line_end) < 0)
return -1;
if (pkt->type == GIT_PKT_ERR) {
git_error_set(GIT_ERROR_NET, "remote error: %s", ((git_pkt_err *)pkt)->error);
git__free(pkt);
......@@ -236,7 +238,9 @@ static int recv_pkt(git_pkt **out_pkt, git_pkt_type *out_type, gitno_buffer *buf
}
} while (error);
gitno_consume(buf, line_end);
if (gitno_consume(buf, line_end) < 0)
return -1;
if (out_type != NULL)
*out_type = pkt->type;
if (out_pkt != NULL)
......@@ -791,7 +795,8 @@ static int parse_report(transport_smart *transport, git_push *push)
continue;
}
gitno_consume(buf, line_end);
if (gitno_consume(buf, line_end) < 0)
return -1;
error = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment