From 8d8944f2e16b8d11e54cb79e1d45023e84aed37f Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Fri, 31 Oct 2014 17:42:06 +0100 Subject: [PATCH] Fix free_connection() moving the wrong memory. --- utcp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utcp.c b/utcp.c index 3206cd7..e64eb24 100644 --- a/utcp.c +++ b/utcp.c @@ -117,9 +117,12 @@ static int32_t seqdiff(uint32_t a, uint32_t b) { // This gives O(log(N)) lookup time, O(N log(N)) insertion time and O(N) deletion time. static int compare(const void *va, const void *vb) { + assert(va && vb); + const struct utcp_connection *a = *(struct utcp_connection **)va; const struct utcp_connection *b = *(struct utcp_connection **)vb; + assert(a && b); assert(a->src && b->src); int c = (int)a->src - (int)b->src; @@ -147,7 +150,7 @@ static void free_connection(struct utcp_connection *c) { assert(cp); int i = cp - utcp->connections; - memmove(cp + i, cp + i + 1, (utcp->nconnections - i - 1) * sizeof *cp); + memmove(cp, cp + 1, (utcp->nconnections - i - 1) * sizeof *cp); utcp->nconnections--; free(c->sndbuf); -- 2.39.5