]> git.meshlink.io Git - utcp/blobdiff - utcp.c
Fix buffer resizing.
[utcp] / utcp.c
diff --git a/utcp.c b/utcp.c
index 6aa985f72701ee2eb0f6e4f1a3f9497cc6ddedd0..3d0971a37ba359716533ddaeab9b03874473d510 100644 (file)
--- a/utcp.c
+++ b/utcp.c
 #undef poll
 #endif
 
+#ifndef UTCP_CLOCK
+#if defined(CLOCK_MONOTONIC_RAW) && defined(__x86_64__)
+#define UTCP_CLOCK CLOCK_MONOTONIC_RAW
+#else
+#define UTCP_CLOCK CLOCK_MONOTONIC
+#endif
+#endif
+
 static void timespec_sub(const struct timespec *a, const struct timespec *b, struct timespec *r) {
        r->tv_sec = a->tv_sec - b->tv_sec;
        r->tv_nsec = a->tv_nsec - b->tv_nsec;
@@ -90,14 +98,6 @@ static inline size_t max(size_t a, size_t b) {
 #define UTCP_DEBUG_DATALEN 20
 #endif
 
-#ifndef UTCP_CLOCK
-#if defined(CLOCK_MONOTONIC_RAW) && defined(__x86_64__)
-#define UTCP_CLOCK CLOCK_MONOTONIC_RAW
-#else
-#define UTCP_CLOCK CLOCK_MONOTONIC
-#endif
-#endif
-
 static void debug(struct utcp_connection *c, const char *format, ...) {
        struct timespec tv;
        char buf[1024];
@@ -220,7 +220,7 @@ static bool buffer_resize(struct buffer *buf, uint32_t newsize) {
                // [345.........|........012]
                uint32_t tailsize = buf->size - buf->offset;
                uint32_t newoffset = newsize - tailsize;
-               memmove(buf + newoffset, buf + buf->offset, tailsize);
+               memmove(buf->data + newoffset, buf->data + buf->offset, tailsize);
                buf->offset = newoffset;
        }