diff options
author | Mattias Andrée <maandree@kth.se> | 2022-06-11 16:37:09 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-06-11 16:37:09 +0200 |
commit | fcfe59c1f2219408ac2a9cd84b386816ff252221 (patch) | |
tree | 0f46c009babfba2d0200ece3ecce067c548a66b6 /memelemmove.c | |
parent | Remove `static` from some `static inline` (diff) | |
download | libsimple-fcfe59c1f2219408ac2a9cd84b386816ff252221.tar.gz libsimple-fcfe59c1f2219408ac2a9cd84b386816ff252221.tar.bz2 libsimple-fcfe59c1f2219408ac2a9cd84b386816ff252221.tar.xz |
Fix warnings, replace some static inline with inline + extern inline, and fix glibc support
Diffstat (limited to '')
-rw-r--r-- | memelemmove.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/memelemmove.c b/memelemmove.c index 7becbc2..d790a87 100644 --- a/memelemmove.c +++ b/memelemmove.c @@ -5,18 +5,19 @@ #define MEMELEMMOVE(TYPE)\ do {\ - TYPE *p;\ + const TYPE *p;\ + TYPE *ret;\ if (d <= s) {\ for (; n; n--, s++)\ if ((*d++ = *s) == elem)\ return d;\ } else {\ - for (p = *(TYPE **)(void *)&s; n; n--, p++) {\ + for (p = s; n; n--, p++) {\ if (*p == elem) {\ n = (size_t)(p - s);\ - p = &d[n + 1];\ + ret = &d[n + 1];\ do { d[n] = s[n]; } while (n--);\ - return p;\ + return ret;\ }\ }\ for (n = (size_t)(p - s); n;) {\ @@ -52,7 +53,8 @@ memelemmove64(uint64_t *restrict d, const uint64_t *restrict s, uint64_t elem, s static char * memelemmovex(char *restrict d, const char *restrict s, const char *restrict elem, size_t width, size_t n) { - char *p; + const char *p; + char *ret; size_t i; if (d <= s) { for (; n; s += width, n--) { @@ -68,26 +70,26 @@ memelemmovex(char *restrict d, const char *restrict s, const char *restrict elem } return NULL; } else { - for (p = *(char **)(void *)&s; n; n--) { + for (p = s; n; n--) { for (i = 0; i < width; i++) if (p[i] != elem[i]) goto next_backwards; p += width; n = (size_t)(p - s); - p = &d[n]; + ret = &d[n]; goto out_backwards; next_backwards: p += width; } n = (size_t)(p - s); - p = NULL; + ret = NULL; out_backwards: while (n) { n--; d[n] = s[n]; } - return p; + return ret; } } @@ -143,7 +145,7 @@ main(void) assert(!strncmp(buf, "-----hello-", 11)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "hello")[0] = '-';; + stpcpy(&buf[5], "hello")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "l", 1, 5) == &buf[5 + 3]); assert(!strncmp(buf, "-----hello-", 11)); @@ -189,7 +191,7 @@ main(void) assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-';; + stpcpy(&buf[5], ".h.e.l.l.o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".l", 2, 5) == &buf[5 + 3 * 2]); assert(!strncmp(buf, "-----.h.e.l.l.o-", 16)); @@ -235,7 +237,7 @@ main(void) assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-';; + stpcpy(&buf[5], "..h..e..l..l..o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "..l", 3, 5) == &buf[5 + 3 * 3]); assert(!strncmp(buf, "-----..h..e..l..l..o-", 21)); @@ -281,7 +283,7 @@ main(void) assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-';; + stpcpy(&buf[5], "...h...e...l...l...o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], "...l", 4, 5) == &buf[5 + 3 * 4]); assert(!strncmp(buf, "-----...h...e...l...l...o-", 26)); @@ -327,7 +329,7 @@ main(void) assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); memset(buf, '-', sizeof(buf)), buf[sizeof(buf) - 1] = '\0'; - stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-';; + stpcpy(&buf[5], ".......h.......e.......l.......l.......o")[0] = '-'; assert(libsimple_memelemmove(&buf[5], &buf[5], ".......l", 8, 5) == &buf[5 + 3 * 8]); assert(!strncmp(buf, "-----.......h.......e.......l.......l.......o-", 46)); |