void *mm_malloc_aligned(void *ctx, size_t n)
{
- size_t alignment = (size_t)ctx;
+ size_t alignment = (uintptr_t)ctx;
void *res;
int err = posix_memalign(&res, alignment, n);
if (err == 0) {
{
assert(__builtin_popcount(alignment) == 1);
mm_ctx_init(mm);
- mm->ctx = (uint8_t *)NULL + alignment; /*< roundabout to satisfy linters */
+ mm->ctx = (void *)(uintptr_t)alignment; /*< roundabout to satisfy linters */
/* posix_memalign() doesn't allow alignment < sizeof(void*),
* and there's no point in using it for small values anyway,
* as plain malloc() guarantees at least max_align_t. */
if (param_count == 1) {
void *val;
if (trie_del(the_network->endpoint_kinds, kind, kind_len, &val) == KNOT_EOK) {
- const int fun_id = (char *)val - (char *)NULL;
+ const int fun_id = (intptr_t)val;
luaL_unref(L, LUA_REGISTRYINDEX, fun_id);
return 0;
}
if (!pp) lua_error_maybe(L, kr_error(ENOMEM));
if (*pp != NULL || !strcasecmp(kind, "dns") || !strcasecmp(kind, "tls"))
lua_error_p(L, "attempt to register known kind '%s'\n", kind);
- *pp = (char *)NULL + fun_id;
+ *pp = (void *)(intptr_t)fun_id;
/* We don't attempt to engage corresponding endpoints now.
* That's the job for network_engage_endpoints() later. */
return 0;
if (!pp) return kr_ok();
/* Now execute the callback. */
- const int fun_id = (char *)*pp - (char *)NULL;
+ const int fun_id = (intptr_t)*pp;
lua_rawgeti(L, LUA_REGISTRYINDEX, fun_id);
lua_pushboolean(L, true /* open */);
lua_pushpointer(L, ep);
}
if (!pp) return;
- const int fun_id = (char *)*pp - (char *)NULL;
+ const int fun_id = (intptr_t)*pp;
lua_rawgeti(L, LUA_REGISTRYINDEX, fun_id);
lua_pushboolean(L, false /* close */);
lua_pushpointer(L, ep);
int kind_unregister(trie_val_t *tv, void *L)
{
- int fun_id = (char *)*tv - (char *)NULL;
+ int fun_id = (intptr_t)*tv;
luaL_unref(L, LUA_REGISTRYINDEX, fun_id);
return 0;
}
/** @internal Return pointer to value in an lru_item. */
static void * item_val(const struct lru *lru, struct lru_item *it)
{
- size_t key_end = it->data + it->key_len - (char *)NULL;
+ size_t key_end = (uintptr_t)(it->data + it->key_len);
size_t val_begin = round_power(key_end, lru->val_alignment);
- return (char *)NULL + val_begin;
+ return (void *)(uintptr_t)val_begin;
}
/** @internal Free each item. */
trie_val_t *data = trie_get_ins(t, dict[i], KEY_LEN(dict[i]));
assert_non_null(data);
assert_null(*data);
- *data = (char *)NULL + i; // yes, ugly
+ *data = (void *)(intptr_t)i; // yes, ugly
assert_ptr_equal(trie_get_try(t, dict[i], KEY_LEN(dict[i])), data);
}
assert_int_equal(trie_weight(t), dict_size);
const char *key = trie_it_key(it, &len);
assert_int_equal(KEY_LEN(key), len);
assert_string_equal(key, dict_sorted[i]);
- assert_ptr_equal(dict[(char *)*trie_it_val(it) - (char *)NULL],
+ assert_ptr_equal(dict[(uintptr_t)*trie_it_val(it)],
dict_sorted[i]);
}
assert_true(trie_it_finished(it));
assert_non_null(key);
assert_int_equal(len, KEY_LEN(key));
assert_non_null(data);
- ptrdiff_t key_i = (char *)*data - (char *)NULL;
+ uintptr_t key_i = (uintptr_t)*data;
assert_string_equal(key, dict[key_i]);
len = 30;
static void assert_portability(void) {
#if FLAGS_HACK
kr_require(((union node){ .leaf = {
- .key = (tkey_t *)(((uint8_t *)NULL) + 1),
+ .key = (tkey_t *)(void *)(uintptr_t)1,
.val = NULL
} }).branch.flags == 1);
#endif