Make payloads into uint8_t.

This will avoid some signed/unsigned assignment-related bugs.
This commit is contained in:
Nick Mathewson
2010-12-13 19:34:01 -05:00
parent 785086cfba
commit b8a7bad799
14 changed files with 130 additions and 115 deletions
+6 -6
View File
@@ -431,7 +431,7 @@ tor_fix_source_file(const char *fname)
* unaligned memory access.
*/
uint16_t
get_uint16(const char *cp)
get_uint16(const void *cp)
{
uint16_t v;
memcpy(&v,cp,2);
@@ -443,7 +443,7 @@ get_uint16(const char *cp)
* unaligned memory access.
*/
uint32_t
get_uint32(const char *cp)
get_uint32(const void *cp)
{
uint32_t v;
memcpy(&v,cp,4);
@@ -455,7 +455,7 @@ get_uint32(const char *cp)
* unaligned memory access.
*/
uint64_t
get_uint64(const char *cp)
get_uint64(const void *cp)
{
uint64_t v;
memcpy(&v,cp,8);
@@ -467,7 +467,7 @@ get_uint64(const char *cp)
* *(uint16_t*)(cp) = v, but will not cause segfaults on platforms that forbid
* unaligned memory access. */
void
set_uint16(char *cp, uint16_t v)
set_uint16(void *cp, uint16_t v)
{
memcpy(cp,&v,2);
}
@@ -476,7 +476,7 @@ set_uint16(char *cp, uint16_t v)
* *(uint32_t*)(cp) = v, but will not cause segfaults on platforms that forbid
* unaligned memory access. */
void
set_uint32(char *cp, uint32_t v)
set_uint32(void *cp, uint32_t v)
{
memcpy(cp,&v,4);
}
@@ -485,7 +485,7 @@ set_uint32(char *cp, uint32_t v)
* *(uint64_t*)(cp) = v, but will not cause segfaults on platforms that forbid
* unaligned memory access. */
void
set_uint64(char *cp, uint64_t v)
set_uint64(void *cp, uint64_t v)
{
memcpy(cp,&v,8);
}
+8 -8
View File
@@ -448,18 +448,18 @@ typedef enum {
/* ===== OS compatibility */
const char *get_uname(void);
uint16_t get_uint16(const char *cp) ATTR_PURE ATTR_NONNULL((1));
uint32_t get_uint32(const char *cp) ATTR_PURE ATTR_NONNULL((1));
uint64_t get_uint64(const char *cp) ATTR_PURE ATTR_NONNULL((1));
void set_uint16(char *cp, uint16_t v) ATTR_NONNULL((1));
void set_uint32(char *cp, uint32_t v) ATTR_NONNULL((1));
void set_uint64(char *cp, uint64_t v) ATTR_NONNULL((1));
uint16_t get_uint16(const void *cp) ATTR_PURE ATTR_NONNULL((1));
uint32_t get_uint32(const void *cp) ATTR_PURE ATTR_NONNULL((1));
uint64_t get_uint64(const void *cp) ATTR_PURE ATTR_NONNULL((1));
void set_uint16(void *cp, uint16_t v) ATTR_NONNULL((1));
void set_uint32(void *cp, uint32_t v) ATTR_NONNULL((1));
void set_uint64(void *cp, uint64_t v) ATTR_NONNULL((1));
/* These uint8 variants are defined to make the code more uniform. */
#define get_uint8(cp) (*(const uint8_t*)(cp))
static void set_uint8(char *cp, uint8_t v);
static void set_uint8(void *cp, uint8_t v);
static INLINE void
set_uint8(char *cp, uint8_t v)
set_uint8(void *cp, uint8_t v)
{
*(uint8_t*)cp = v;
}