#define PAGE_OFFSET_U64(l) ALIGN_OFFSET_U64(l, page_size())
/* Normal memcpy() requires src to be nonnull. We do nothing if n is 0. */
-static inline void *memcpy_safe(void *dst, const void *src, size_t n) {
+static inline void* memcpy_safe(void *dst, const void *src, size_t n) {
if (n == 0)
return dst;
assert(src);
}
/* Normal mempcpy() requires src to be nonnull. We do nothing if n is 0. */
-static inline void *mempcpy_safe(void *dst, const void *src, size_t n) {
+static inline void* mempcpy_safe(void *dst, const void *src, size_t n) {
if (n == 0)
return dst;
assert(src);
return mempcpy(dst, src, n);
}
+#define mempcpy_typesafe(dst, src, n) (typeof((dst)[0])*) mempcpy_safe(dst, src, n)
+
/* Normal memcmp() requires s1 and s2 to be nonnull. We do nothing if n is 0. */
static inline int memcmp_safe(const void *s1, const void *s2, size_t n) {
if (n == 0)
char *buf = malloc(strlen("COREDUMP_PROC_AUXV=") + size + 1);
if (buf) {
/* Add a dummy terminator to make save_context() happy. */
- *((uint8_t*) mempcpy(stpcpy(buf, "COREDUMP_PROC_AUXV="), t, size)) = '\0';
+ *mempcpy_typesafe(stpcpy(buf, "COREDUMP_PROC_AUXV="), t, size) = '\0';
(void) iovw_consume(iovw, buf, size + strlen("COREDUMP_PROC_AUXV="));
}
if (!c)
return -ENOMEM;
- *((char*) mempcpy(stpcpy(c, field), s, e - s)) = 0;
+ *mempcpy_typesafe(stpcpy(c, field), s, e - s) = 0;
e += 1;
iovec[n++] = IOVEC_MAKE_STRING(k); \
}
-#define IOVEC_ADD_SIZED_FIELD(iovec, n, value, value_size, field) \
- if (value_size > 0) { \
- char *k; \
- k = newa(char, STRLEN(field "=") + value_size + 1); \
- *((char*) mempcpy(stpcpy(k, field "="), value, value_size)) = 0; \
- iovec[n++] = IOVEC_MAKE_STRING(k); \
- } \
+#define IOVEC_ADD_SIZED_FIELD(iovec, n, value, value_size, field) \
+ if (value_size > 0) { \
+ char *k; \
+ k = newa(char, STRLEN(field "=") + value_size + 1); \
+ *mempcpy_typesafe(stpcpy(k, field "="), value, value_size) = 0; \
+ iovec[n++] = IOVEC_MAKE_STRING(k); \
+ }
static void server_dispatch_message_real(
Server *s,
};
/* Just to be extra paranoid, let's NUL terminate the downloaded buffer */
- *(uint8_t*) mempcpy(item->data, data, size) = 0;
+ *mempcpy_typesafe(item->data, data, size) = 0;
web_cache_item_free(hashmap_remove(*web_cache, url));
if (!w)
return -ENOMEM;
- *(char*) mempcpy(stpcpy(stpcpy(mempcpy(w, s, a), prepend), c->local_rtc ? "LOCAL" : "UTC"), e, b) = 0;
+ *mempcpy_typesafe(stpcpy(stpcpy(mempcpy(w, s, a), prepend), c->local_rtc ? "LOCAL" : "UTC"), e, b) = 0;
if (streq(w, NULL_ADJTIME_UTC)) {
if (unlink("/etc/adjtime") < 0)
e = s + strcspn(s, "/");
/* Copy the path component to t so it can be a null terminated string. */
- *((char*) mempcpy(t, s, e - s)) = 0;
+ *mempcpy_typesafe(t, s, e - s) = 0;
/* Is this the last component? If so, then check the type */
if (*e == 0)