diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2019-03-20 18:54:11 +0200 |
---|---|---|
committer | rl1987 <rl1987@sdf.lonestar.org> | 2019-03-20 18:54:11 +0200 |
commit | 0bc9ed9d38cb29783d000b6e22677ae16727976b (patch) | |
tree | 2866abc10a0910d10f071506e14297e40609d8c4 /src/test/ptr_helpers.c | |
parent | e52653e01a2ce6655975c2f893a1d1ff7bef2af7 (diff) | |
download | tor-0bc9ed9d38cb29783d000b6e22677ae16727976b.tar.gz tor-0bc9ed9d38cb29783d000b6e22677ae16727976b.zip |
Move casts to separate C file to prevent compiler from optimising them away
Diffstat (limited to 'src/test/ptr_helpers.c')
-rw-r--r-- | src/test/ptr_helpers.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/test/ptr_helpers.c b/src/test/ptr_helpers.c new file mode 100644 index 0000000000..296238feeb --- /dev/null +++ b/src/test/ptr_helpers.c @@ -0,0 +1,50 @@ +/* Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#include "ptr_helpers.h" + +/** + * Cast <b> (inptr_t value) to a void pointer. + */ +void * +cast_intptr_to_voidstar(intptr_t x) +{ + void *r = (void *)x; + + return r; +} + +/** + * Cast x (void pointer) to inptr_t value. + */ +intptr_t +cast_voidstar_to_intptr(void *x) +{ + intptr_t r = (intptr_t)x; + + return r; +} + +/** + * Cast x (uinptr_t value) to void pointer. + */ +void * +cast_uintptr_to_voidstar(uintptr_t x) +{ + void *r = (void *)x; + + return r; +} + +/** + * Cast x (void pointer) to uinptr_t value. + */ +uintptr_t +cast_voidstar_to_uintptr(void *x) +{ + uintptr_t r = (uintptr_t)x; + + return r; +} |