summaryrefslogtreecommitdiffstats
path: root/src/util/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/util.h')
-rw-r--r--src/util/util.h62
1 files changed, 1 insertions, 61 deletions
diff --git a/src/util/util.h b/src/util/util.h
index 49dc850c3..fa45fdfdf 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -45,6 +45,7 @@
#include "util/atomic_io.h"
#include "util/util_errors.h"
+#include "util/util_safealign.h"
#define _(STRING) gettext (STRING)
@@ -270,67 +271,6 @@ errno_t set_debug_file_from_fd(const int fd);
#define OUT_OF_ID_RANGE(id, min, max) \
(id == 0 || (min && (id < min)) || (max && (id > max)))
-#define SIZE_T_MAX ((size_t) -1)
-
-#define SIZE_T_OVERFLOW(current, add) \
- (((size_t)(add)) > (SIZE_T_MAX - ((size_t)(current))))
-
-static inline void
-safealign_memcpy(void *dest, const void *src, size_t n, size_t *counter)
-{
- memcpy(dest, src, n);
- if (counter) {
- *counter += n;
- }
-}
-
-#define SAFEALIGN_SET_VALUE(dest, value, type, pctr) do { \
- type CV_MACRO_val = (type)(value); \
- safealign_memcpy(dest, &CV_MACRO_val, sizeof(type), pctr); \
-} while(0)
-
-#define SAFEALIGN_COPY_INT64(dest, src, pctr) \
- safealign_memcpy(dest, src, sizeof(int64_t), pctr)
-
-#define SAFEALIGN_SET_INT64(dest, value, pctr) \
- SAFEALIGN_SET_VALUE(dest, value, int64_t, pctr)
-
-#define SAFEALIGN_COPY_UINT32(dest, src, pctr) \
- safealign_memcpy(dest, src, sizeof(uint32_t), pctr)
-
-#define SAFEALIGN_SET_UINT32(dest, value, pctr) \
- SAFEALIGN_SET_VALUE(dest, value, uint32_t, pctr)
-
-#define SAFEALIGN_COPY_INT32(dest, src, pctr) \
- safealign_memcpy(dest, src, sizeof(int32_t), pctr)
-
-#define SAFEALIGN_SET_INT32(dest, value, pctr) \
- SAFEALIGN_SET_VALUE(dest, value, int32_t, pctr)
-
-#define SAFEALIGN_COPY_UINT16(dest, src, pctr) \
- safealign_memcpy(dest, src, sizeof(uint16_t), pctr)
-
-#define SAFEALIGN_SET_UINT16(dest, value, pctr) \
- SAFEALIGN_SET_VALUE(dest, value, uint16_t, pctr)
-
-#define SAFEALIGN_COPY_UINT32_CHECK(dest, src, len, pctr) do { \
- if ((*(pctr) + sizeof(uint32_t)) > (len) || \
- SIZE_T_OVERFLOW(*(pctr), sizeof(uint32_t))) return EINVAL; \
- safealign_memcpy(dest, src, sizeof(uint32_t), pctr); \
-} while(0)
-
-#define SAFEALIGN_COPY_INT32_CHECK(dest, src, len, pctr) do { \
- if ((*(pctr) + sizeof(int32_t)) > (len) || \
- SIZE_T_OVERFLOW(*(pctr), sizeof(int32_t))) return EINVAL; \
- safealign_memcpy(dest, src, sizeof(int32_t), pctr); \
-} while(0)
-
-#define SAFEALIGN_COPY_UINT16_CHECK(dest, src, len, pctr) do { \
- if ((*(pctr) + sizeof(uint16_t)) > (len) || \
- SIZE_T_OVERFLOW(*(pctr), sizeof(uint16_t))) return EINVAL; \
- safealign_memcpy(dest, src, sizeof(uint16_t), pctr); \
-} while(0)
-
#include "util/dlinklist.h"
/* From debug.c */