summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichal Zidek <mzidek@redhat.com>2013-08-26 13:58:37 +0200
committerJakub Hrozek <jhrozek@redhat.com>2013-09-05 11:13:29 +0200
commit747f30f1665a4dfcfe61a850b2e333a8bd35259b (patch)
tree6d55dc8e9fdfb84a4d6c7f3d5874826de5cbb9d4 /src
parent3ae2e9971ad97227f644e59ad838419092f0902a (diff)
downloadsssd-747f30f1665a4dfcfe61a850b2e333a8bd35259b.tar.gz
sssd-747f30f1665a4dfcfe61a850b2e333a8bd35259b.tar.bz2
sssd-747f30f1665a4dfcfe61a850b2e333a8bd35259b.zip
Rename SAFEALIGN macros
The new SAFEALIGN macros name turned to be inappropriate because they do not reflect what the macros really do.
Diffstat (limited to 'src')
-rw-r--r--src/util/util_safealign.h70
1 files changed, 40 insertions, 30 deletions
diff --git a/src/util/util_safealign.h b/src/util/util_safealign.h
index e7f34e14..c39ba159 100644
--- a/src/util/util_safealign.h
+++ b/src/util/util_safealign.h
@@ -44,66 +44,76 @@ safealign_memcpy(void *dest, const void *src, size_t n, size_t *counter)
}
}
-#define SAFEALIGN_VAR2BUF(dest, value, type, pctr) do { \
+#define SAFEALIGN_SETMEM_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_BUF2VAR_INT64(dest, src, pctr) \
+/* SAFEALIGN_COPY_INT64(void *dest, void *src, size_t *pctr)
+ * This macro will safely copy sizeof(int64_t) bytes from memory
+ * location pointed by 'src' to memory location pointed by 'dest'.
+ * If the 'pctr' pointer is not NULL, the value it points to will
+ * be incremented by sizeof(int64_t). */
+#define SAFEALIGN_COPY_INT64(dest, src, pctr) \
safealign_memcpy(dest, src, sizeof(int64_t), pctr)
-#define SAFEALIGN_VAR2BUF_INT64(dest, value, pctr) \
- SAFEALIGN_VAR2BUF(dest, value, int64_t, pctr)
+/* SAFEALIGN_SETMEM_INT64(void *dest, int64_t value, size_t *pctr)
+ * This macro will safely assign an int64_t value to the memory
+ * location pointed by 'dest'. If the 'pctr' pointer is not NULL,
+ * the value it points to will be incremented by sizeof(int64_t). */
+#define SAFEALIGN_SETMEM_INT64(dest, value, pctr) \
+ SAFEALIGN_SETMEM_VALUE(dest, value, int64_t, pctr)
-#define SAFEALIGN_BUF2VAR_UINT32(dest, src, pctr) \
+/* SAFEALIGN_COPY_UINT32(void *dest, void *src, size_t *pctr) */
+#define SAFEALIGN_COPY_UINT32(dest, src, pctr) \
safealign_memcpy(dest, src, sizeof(uint32_t), pctr)
-#define SAFEALIGN_VAR2BUF_UINT32(dest, value, pctr) \
- SAFEALIGN_VAR2BUF(dest, value, uint32_t, pctr)
+/* SAFEALIGN_SETMEM_UINT32(void *dest, uint32_t value, size_t *pctr) */
+#define SAFEALIGN_SETMEM_UINT32(dest, value, pctr) \
+ SAFEALIGN_SETMEM_VALUE(dest, value, uint32_t, pctr)
-#define SAFEALIGN_BUF2VAR_INT32(dest, src, pctr) \
+/* SAFEALIGN_COPY_INT32(void *dest, void *src, size_t *pctr) */
+#define SAFEALIGN_COPY_INT32(dest, src, pctr) \
safealign_memcpy(dest, src, sizeof(int32_t), pctr)
-#define SAFEALIGN_VAR2BUF_INT32(dest, value, pctr) \
- SAFEALIGN_VAR2BUF(dest, value, int32_t, pctr)
+/* SAFEALIGN_SETMEM_INT32(void *dest, int32_t value, size_t *pctr) */
+#define SAFEALIGN_SETMEM_INT32(dest, value, pctr) \
+ SAFEALIGN_SETMEM_VALUE(dest, value, int32_t, pctr)
-#define SAFEALIGN_BUF2VAR_UINT16(dest, src, pctr) \
+/* SAFEALIGN_COPY_UINT16(void *dest, void *src, size_t *pctr) */
+#define SAFEALIGN_COPY_UINT16(dest, src, pctr) \
safealign_memcpy(dest, src, sizeof(uint16_t), pctr)
-#define SAFEALIGN_VAR2BUF_UINT16(dest, value, pctr) \
- SAFEALIGN_VAR2BUF(dest, value, uint16_t, pctr)
+/* SAFEALIGN_SETMEM_UINT16(void *dest, uint16_t value, size_t *pctr) */
+#define SAFEALIGN_SETMEM_UINT16(dest, value, pctr) \
+ SAFEALIGN_SETMEM_VALUE(dest, value, uint16_t, pctr)
-#define SAFEALIGN_BUF2VAR_UINT32_CHECK(dest, src, len, pctr) do { \
+/* These macros are the same as their equivalents without _CHECK suffix,
+ * but additionally make the caller return EINVAL immediatelly if *pctr
+ * would excceed len. */
+#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_BUF2VAR_INT32_CHECK(dest, src, len, pctr) do { \
+#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_BUF2VAR_UINT16_CHECK(dest, src, len, pctr) do { \
+#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)
-
-/* Do not use these aliases in new code. Use the macros above instead. */
-#define SAFEALIGN_SET_VALUE SAFEALIGN_VAR2BUF
-#define SAFEALIGN_COPY_INT64 SAFEALIGN_BUF2VAR_INT64
-#define SAFEALIGN_SET_INT64 SAFEALIGN_VAR2BUF_INT64
-#define SAFEALIGN_COPY_UINT32 SAFEALIGN_BUF2VAR_UINT32
-#define SAFEALIGN_SET_UINT32 SAFEALIGN_VAR2BUF_UINT32
-#define SAFEALIGN_COPY_INT32 SAFEALIGN_BUF2VAR_INT32
-#define SAFEALIGN_SET_INT32 SAFEALIGN_VAR2BUF_INT32
-#define SAFEALIGN_COPY_UINT16 SAFEALIGN_BUF2VAR_UINT16
-#define SAFEALIGN_SET_UINT16 SAFEALIGN_VAR2BUF_UINT16
-#define SAFEALIGN_COPY_UINT32_CHECK SAFEALIGN_BUF2VAR_UINT32_CHECK
-#define SAFEALIGN_COPY_INT32_CHECK SAFEALIGN_BUF2VAR_INT32_CHECK
-#define SAFEALIGN_COPY_UINT16_CHECK SAFEALIGN_BUF2VAR_UINT16_CHECK
+/* Aliases for backward compatibility. */
+#define SAFEALIGN_SET_VALUE SAFEALIGN_SETMEM_VALUE
+#define SAFEALIGN_SET_INT64 SAFEALIGN_SETMEM_INT64
+#define SAFEALIGN_SET_UINT32 SAFEALIGN_SETMEM_UINT32
+#define SAFEALIGN_SET_INT32 SAFEALIGN_SETMEM_INT32
+#define SAFEALIGN_SET_UINT16 SAFEALIGN_SETMEM_UINT16
#endif /* _UTIL_SAFEALIGN_H */