portability: Avoid void* arithmetics which is a GNU extension

Under GNU C, sizeof(void) = 1. This commit merely makes it explicit u8.

Pointer arithmetics over void types is:
 * A GNU C extension
 * Not supported by Clang
 * Illegal across all ISO C standards

See also: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
This commit is contained in:
Mark Ruvald Pedersen 2018-09-14 14:24:09 +02:00 committed by Anas Nashif
commit d67096da05
23 changed files with 62 additions and 55 deletions

View file

@ -408,7 +408,7 @@ static FUNC_NORETURN __used void _df_handler_bottom(void)
* one byte, since if a single push operation caused the fault ESP
* wouldn't be decremented
*/
_x86_mmu_get_flags((void *)_df_esf.esp - 1, &pde_flags, &pte_flags);
_x86_mmu_get_flags((u8_t *)_df_esf.esp - 1, &pde_flags, &pte_flags);
if (pte_flags & MMU_ENTRY_PRESENT) {
printk("***** Double Fault *****\n");
reason = _NANO_ERR_CPU_EXCEPTION;

View file

@ -118,7 +118,7 @@ static int flash_stm32_read(struct device *dev, off_t offset, void *data,
return 0;
}
memcpy(data, (void *) CONFIG_FLASH_BASE_ADDRESS + offset, len);
memcpy(data, (u8_t *) CONFIG_FLASH_BASE_ADDRESS + offset, len);
return 0;
}

View file

@ -217,7 +217,8 @@ static int flash_nios2_qspi_write_block(struct device *dev, int block_offset,
/* prepare the word to be written */
memcpy((u8_t *)&word_to_write + padding,
data + buffer_offset, bytes_to_copy);
(const u8_t *)data + buffer_offset,
bytes_to_copy);
/* enable write */
IOWR_32DIRECT(qspi_dev->csr_base,
@ -298,7 +299,8 @@ static int flash_nios2_qspi_write(struct device *dev, off_t offset,
rc = flash_nios2_qspi_write_block(dev,
block_offset, write_offset,
data + buffer_offset, length_to_write);
(const u8_t *)data + buffer_offset,
length_to_write);
if (rc < 0) {
goto qspi_write_err;
}
@ -347,7 +349,8 @@ static int flash_nios2_qspi_read(struct device *dev, off_t offset,
/* read from flash 32 bits at a time */
word_to_read = IORD_32DIRECT(qspi_dev->data_base, read_offset);
memcpy(data + buffer_offset, &word_to_read, bytes_to_copy);
memcpy((u8_t *)data + buffer_offset, &word_to_read,
bytes_to_copy);
/* update offset and length variables */
read_offset += bytes_to_copy;

View file

@ -340,7 +340,7 @@ static inline u8_t *get_mac(struct device *dev)
#if defined(CONFIG_IEEE802154_UPIPE_RANDOM_MAC)
UNALIGNED_PUT(sys_cpu_to_be32(sys_rand32_get()),
(u32_t *) ((void *)upipe->mac_addr+4));
(u32_t *) ((u8_t *)upipe->mac_addr+4));
#else
upipe->mac_addr[4] = CONFIG_IEEE802154_UPIPE_MAC4;
upipe->mac_addr[5] = CONFIG_IEEE802154_UPIPE_MAC5;

View file

@ -157,7 +157,7 @@ static void spi_sam0_finish(SercomSpi *regs)
static void spi_sam0_fast_tx(SercomSpi *regs, const struct spi_buf *tx_buf)
{
const u8_t *p = tx_buf->buf;
const u8_t *pend = tx_buf->buf + tx_buf->len;
const u8_t *pend = (u8_t *)tx_buf->buf + tx_buf->len;
u8_t ch;
while (p != pend) {
@ -215,7 +215,7 @@ static void spi_sam0_fast_txrx(SercomSpi *regs,
const struct spi_buf *rx_buf)
{
const u8_t *tx = tx_buf->buf;
const u8_t *txend = tx_buf->buf + tx_buf->len;
const u8_t *txend = (u8_t *)tx_buf->buf + tx_buf->len;
u8_t *rx = rx_buf->buf;
size_t len = rx_buf->len;

View file

@ -345,8 +345,8 @@ int usb_dc_ep_configure(const struct usb_dc_ep_cfg_data * const cfg)
bdt[idx_even].buf_addr = (u32_t)block->data;
SYS_LOG_INF("idx_even %x", (u32_t)block->data);
bdt[idx_odd].buf_addr = (u32_t)(block->data + cfg->ep_mps);
SYS_LOG_INF("idx_odd %x", (u32_t)(block->data + cfg->ep_mps));
bdt[idx_odd].buf_addr = (u32_t)((u8_t *)block->data + cfg->ep_mps);
SYS_LOG_INF("idx_odd %x", (u32_t)((u8_t *)block->data + cfg->ep_mps));
if (cfg->ep_addr & USB_EP_DIR_IN) {
dev_data.ep_ctrl[ep_idx].mps_in = cfg->ep_mps;

View file

@ -148,7 +148,7 @@ static inline const struct log_backend *log_backend_get(u32_t idx)
*/
static inline int log_backend_count_get(void)
{
return ((void *)__log_backends_end - (void *)__log_backends_start) /
return ((u8_t *)__log_backends_end - (u8_t *)__log_backends_start) /
sizeof(struct log_backend);
}

View file

@ -336,7 +336,7 @@ static inline u8_t log_compiled_level_get(u32_t source_id)
static inline u32_t log_const_source_id(
const struct log_source_const_data *data)
{
return ((char *)data - (char *)__log_const_start)/
return ((u8_t *)data - (u8_t *)__log_const_start)/
sizeof(struct log_source_const_data);
}
@ -378,7 +378,7 @@ static inline u32_t *log_dynamic_filters_get(u32_t source_id)
*/
static inline u32_t log_dynamic_source_id(struct log_source_dynamic_data *data)
{
return ((char *)data - (char *)__log_dynamic_start)/
return ((u8_t *)data - (u8_t *)__log_dynamic_start)/
sizeof(struct log_source_dynamic_data);
}

View file

@ -627,7 +627,7 @@ int _impl_k_pipe_get(struct k_pipe *pipe, void *data, size_t bytes_to_read,
sys_dlist_get(&xfer_list);
while ((thread != NULL) && (num_bytes_read < bytes_to_read)) {
desc = (struct k_pipe_desc *)thread->base.swap_data;
bytes_copied = pipe_xfer(data + num_bytes_read,
bytes_copied = pipe_xfer((u8_t *)data + num_bytes_read,
bytes_to_read - num_bytes_read,
desc->buffer, desc->bytes_to_xfer);
@ -651,7 +651,7 @@ int _impl_k_pipe_get(struct k_pipe *pipe, void *data, size_t bytes_to_read,
if ((writer != NULL) && (num_bytes_read < bytes_to_read)) {
desc = (struct k_pipe_desc *)writer->base.swap_data;
bytes_copied = pipe_xfer(data + num_bytes_read,
bytes_copied = pipe_xfer((u8_t *)data + num_bytes_read,
bytes_to_read - num_bytes_read,
desc->buffer, desc->bytes_to_xfer);
@ -700,7 +700,7 @@ int _impl_k_pipe_get(struct k_pipe *pipe, void *data, size_t bytes_to_read,
struct k_pipe_desc pipe_desc;
pipe_desc.buffer = data + num_bytes_read;
pipe_desc.buffer = (u8_t *)data + num_bytes_read;
pipe_desc.bytes_to_xfer = bytes_to_read - num_bytes_read;
if (timeout != K_NO_WAIT) {

View file

@ -203,7 +203,7 @@ void *memmove(void *d, const void *s, size_t n)
char *dest = d;
const char *src = s;
if ((size_t) (d - s) < n) {
if ((size_t) (dest - src) < n) {
/*
* The <src> buffer overlaps with the start of the <dest> buffer.
* Copy backwards to prevent the premature corruption of <src>.

View file

@ -17,12 +17,12 @@ static bool level_empty(struct sys_mem_pool_base *p, int l)
static void *block_ptr(struct sys_mem_pool_base *p, size_t lsz, int block)
{
return p->buf + lsz * block;
return (u8_t *)p->buf + lsz * block;
}
static int block_num(struct sys_mem_pool_base *p, void *block, int sz)
{
return (block - p->buf) / sz;
return ((u8_t *)block - (u8_t *)p->buf) / sz;
}
/* Places a 32 bit output pointer in word, and an integer bit index
@ -73,14 +73,14 @@ static size_t buf_size(struct sys_mem_pool_base *p)
static bool block_fits(struct sys_mem_pool_base *p, void *block, size_t bsz)
{
return (block + bsz - 1 - p->buf) < buf_size(p);
return ((u8_t *)block + bsz - 1 - (u8_t *)p->buf) < buf_size(p);
}
void _sys_mem_pool_base_init(struct sys_mem_pool_base *p)
{
int i;
size_t buflen = p->n_max * p->max_sz, sz = p->max_sz;
u32_t *bits = p->buf + buflen;
u32_t *bits = (u32_t *)((u8_t *)p->buf + buflen);
p->max_inline_level = -1;

View file

@ -13,16 +13,18 @@
int bt_rand(void *buf, size_t len)
{
u8_t *buf8 = buf;
while (len) {
u32_t v = sys_rand32_get();
if (len >= sizeof(v)) {
memcpy(buf, &v, sizeof(v));
memcpy(buf8, &v, sizeof(v));
buf += sizeof(v);
buf8 += sizeof(v);
len -= sizeof(v);
} else {
memcpy(buf, &v, len);
memcpy(buf8, &v, len);
break;
}
}

View file

@ -389,7 +389,7 @@ ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
BT_DBG("handle 0x%04x offset %u length %u", attr->handle, offset,
len);
memcpy(buf, value + offset, len);
memcpy(buf, (u8_t *)value + offset, len);
return len;
}
@ -1408,7 +1408,7 @@ static u16_t parse_include(struct bt_conn *conn, const void *pdu,
/* Parse include found */
for (length--, pdu = rsp->data; length >= rsp->len;
length -= rsp->len, pdu += rsp->len) {
length -= rsp->len, pdu = (const u8_t *)pdu + rsp->len) {
struct bt_gatt_attr *attr;
const struct bt_att_data *data = pdu;
struct gatt_incl *incl = (void *)data->value;
@ -1501,7 +1501,7 @@ static u16_t parse_characteristic(struct bt_conn *conn, const void *pdu,
/* Parse characteristics found */
for (length--, pdu = rsp->data; length >= rsp->len;
length -= rsp->len, pdu += rsp->len) {
length -= rsp->len, pdu = (const u8_t *)pdu + rsp->len) {
struct bt_gatt_attr *attr;
const struct bt_att_data *data = pdu;
struct gatt_chrc *chrc = (void *)data->value;
@ -1629,7 +1629,7 @@ static u16_t parse_service(struct bt_conn *conn, const void *pdu,
/* Parse services found */
for (length--, pdu = rsp->data; length >= rsp->len;
length -= rsp->len, pdu += rsp->len) {
length -= rsp->len, pdu = (const u8_t *)pdu + rsp->len) {
struct bt_gatt_attr attr = {};
struct bt_gatt_service_val value;
const struct bt_att_group_data *data = pdu;
@ -1774,7 +1774,7 @@ static void gatt_find_info_rsp(struct bt_conn *conn, u8_t err,
/* Parse descriptors found */
for (length--, pdu = rsp->info; length >= len;
length -= len, pdu += len) {
length -= len, pdu = (const u8_t *)pdu + len) {
struct bt_gatt_attr *attr;
info.i16 = pdu;
@ -2126,7 +2126,7 @@ static int gatt_prepare_write(struct bt_conn *conn,
/* Update params */
params->offset += len;
params->data += len;
params->data = (const u8_t *)params->data + len;
params->length -= len;
BT_DBG("handle 0x%04x offset %u len %u", params->handle, params->offset,

View file

@ -224,7 +224,7 @@ static void clear_ecc_events(struct net_buf *buf)
{
struct bt_hci_cp_le_set_event_mask *cmd;
cmd = (void *)buf->data + sizeof(struct bt_hci_cmd_hdr);
cmd = (void *)(buf->data + sizeof(struct bt_hci_cmd_hdr));
/*
* don't enable controller ECC events as those will be generated from

View file

@ -29,6 +29,7 @@ static inline size_t _nvs_al_size(struct nvs_fs *fs, size_t len)
static int _nvs_flash_al_wrt(struct nvs_fs *fs, u32_t addr, const void *data,
size_t len)
{
const u8_t *data8 = (const u8_t *)data;
int rc = 0;
off_t offset;
size_t blen;
@ -50,17 +51,17 @@ static int _nvs_flash_al_wrt(struct nvs_fs *fs, u32_t addr, const void *data,
}
blen = len & ~(fs->write_block_size - 1);
if (blen > 0) {
rc = flash_write(fs->flash_device, offset, data, blen);
rc = flash_write(fs->flash_device, offset, data8, blen);
if (rc) {
/* flash write error */
goto end;
}
len -= blen;
offset += blen;
data += blen;
data8 += blen;
}
if (len) {
memcpy(buf, data, len);
memcpy(buf, data8, len);
(void)memset(buf + len, 0xff, fs->write_block_size - len);
rc = flash_write(fs->flash_device, offset, buf,
fs->write_block_size);
@ -132,6 +133,7 @@ static int _nvs_flash_ate_rd(struct nvs_fs *fs, u32_t addr,
static int _nvs_flash_block_cmp(struct nvs_fs *fs, u32_t addr, const void *data,
size_t len)
{
const u8_t *data8 = (const u8_t *)data;
int rc;
size_t bytes_to_cmp, block_size;
u8_t buf[NVS_BLOCK_SIZE];
@ -143,13 +145,13 @@ static int _nvs_flash_block_cmp(struct nvs_fs *fs, u32_t addr, const void *data,
if (rc) {
return rc;
}
rc = memcmp(data, buf, bytes_to_cmp);
rc = memcmp(data8, buf, bytes_to_cmp);
if (rc) {
return 1;
}
len -= bytes_to_cmp;
addr += bytes_to_cmp;
data += bytes_to_cmp;
data8 += bytes_to_cmp;
}
return 0;
}

View file

@ -698,7 +698,7 @@ int net_buf_linearize(void *dst, size_t dst_len, struct net_buf *src,
copied = 0;
while (frag && len > 0) {
to_copy = min(len, frag->len - offset);
memcpy(dst + copied, frag->data + offset, to_copy);
memcpy((u8_t *)dst + copied, frag->data + offset, to_copy);
copied += to_copy;
@ -727,15 +727,15 @@ size_t net_buf_append_bytes(struct net_buf *buf, size_t len,
{
struct net_buf *frag = net_buf_frag_last(buf);
size_t added_len = 0;
const u8_t *value8 = value;
do {
u16_t count = min(len, net_buf_tailroom(frag));
net_buf_add_mem(frag, value, count);
net_buf_add_mem(frag, value8, count);
len -= count;
added_len += count;
value += count;
value8 += count;
if (len == 0) {
return added_len;

View file

@ -63,7 +63,7 @@ static inline struct net_nbr *get_nbr(struct net_nbr *start, int idx)
{
NET_ASSERT(idx < CONFIG_NET_IPV6_MAX_NEIGHBORS);
return (struct net_nbr *)((void *)start +
return (struct net_nbr *)((u8_t *)start +
((sizeof(struct net_nbr) +
start->size + start->extra_data_size) * idx));
}

View file

@ -65,7 +65,7 @@ static inline struct net_nbr *get_nexthop_nbr(struct net_nbr *start, int idx)
NET_ASSERT_INFO(idx < CONFIG_NET_MAX_NEXTHOPS, "idx %d >= max %d",
idx, CONFIG_NET_MAX_NEXTHOPS);
return (struct net_nbr *)((void *)start +
return (struct net_nbr *)((u8_t *)start +
((sizeof(struct net_nbr) + start->size) * idx));
}

View file

@ -233,7 +233,7 @@ static enum net_verdict ieee802154_recv(struct net_if *iface,
ieee802154_acknowledge(iface, &mpdu);
net_pkt_set_ll_reserve(pkt, mpdu.payload - (void *)net_pkt_ll(pkt));
net_pkt_set_ll_reserve(pkt, (u8_t *)mpdu.payload - net_pkt_ll(pkt));
net_buf_pull(pkt->frags, net_pkt_ll_reserve(pkt));
set_pkt_ll_addr(net_pkt_lladdr_src(pkt), mpdu.mhr.fs->fc.pan_id_comp,

View file

@ -44,8 +44,8 @@ static inline const struct shell_cmd_entry *shell_root_cmd_get(u32_t id)
static inline u32_t shell_root_cmd_count(void)
{
return ((void *)__shell_root_cmds_end -
(void *)__shell_root_cmds_start)/
return ((u8_t *)__shell_root_cmds_end -
(u8_t *)__shell_root_cmds_start)/
sizeof(struct shell_cmd_entry);
}

View file

@ -27,8 +27,8 @@ void reset_flag(void);
void reset_multi_pte_page_flag(void);
void reset_multi_pde_flag(void);
#define ADDR_PAGE_1 ((void *)__bss_start + SKIP_SIZE * MMU_PAGE_SIZE)
#define ADDR_PAGE_2 ((void *)__bss_start + (SKIP_SIZE + 1) * MMU_PAGE_SIZE)
#define ADDR_PAGE_1 ((u8_t *)__bss_start + SKIP_SIZE * MMU_PAGE_SIZE)
#define ADDR_PAGE_2 ((u8_t *)__bss_start + (SKIP_SIZE + 1) * MMU_PAGE_SIZE)
#define PRESET_PAGE_1_VALUE (X86_MMU_GET_PTE(ADDR_PAGE_1)->p = 1)
#define PRESET_PAGE_2_VALUE (X86_MMU_GET_PTE(ADDR_PAGE_2)->p = 1)

View file

@ -340,7 +340,7 @@ static void net_buf_test_big_buf(void)
}
ipv6 = (struct ipv6_hdr *)(frag->data - net_buf_headroom(frag));
udp = (struct udp_hdr *)((void *)ipv6 + sizeof(*ipv6));
udp = (struct udp_hdr *)((u8_t *)ipv6 + sizeof(*ipv6));
net_buf_frag_add(buf, frag);
net_buf_unref(buf);
@ -393,7 +393,7 @@ static void net_buf_test_multi_frags(void)
}
ipv6 = (struct ipv6_hdr *)(frags[i]->data - net_buf_headroom(frags[i]));
udp = (struct udp_hdr *)((void *)ipv6 + sizeof(*ipv6));
udp = (struct udp_hdr *)((u8_t *)ipv6 + sizeof(*ipv6));
net_buf_unref(buf);

View file

@ -77,7 +77,7 @@ static void test_ipv6_multi_frags(void)
/* Place the IP + UDP header in the first fragment */
if (!net_buf_tailroom(frag)) {
ipv6 = (struct ipv6_hdr *)(frag->data);
udp = (struct udp_hdr *)((void *)ipv6 + sizeof(*ipv6));
udp = (struct udp_hdr *)((u8_t *)ipv6 + sizeof(*ipv6));
if (net_buf_tailroom(frag) < sizeof(ipv6)) {
printk("Not enough space for IPv6 header, "
"needed %zd bytes, has %zd bytes\n",
@ -93,7 +93,7 @@ static void test_ipv6_multi_frags(void)
zassert_true(false, "No space for UDP header");
}
net_pkt_set_appdata(pkt, (void *)udp + sizeof(*udp));
net_pkt_set_appdata(pkt, (u8_t *)udp + sizeof(*udp));
net_pkt_set_appdatalen(pkt, 0);
}
@ -198,7 +198,7 @@ static void test_fragment_copy(void)
/* Place the IP + UDP header in the first fragment */
if (net_buf_tailroom(frag)) {
ipv6 = (struct ipv6_hdr *)(frag->data);
udp = (struct udp_hdr *)((void *)ipv6 + sizeof(*ipv6));
udp = (struct udp_hdr *)((u8_t *)ipv6 + sizeof(*ipv6));
if (net_buf_tailroom(frag) < sizeof(*ipv6)) {
printk("Not enough space for IPv6 header, "
"needed %zd bytes, has %zd bytes\n",
@ -218,7 +218,7 @@ static void test_fragment_copy(void)
memcpy(net_buf_add(frag, 15), example_data, 15);
net_pkt_set_appdata(pkt, (void *)udp + sizeof(*udp) + 15);
net_pkt_set_appdata(pkt, (u8_t *)udp + sizeof(*udp) + 15);
net_pkt_set_appdatalen(pkt, 0);
}
@ -332,7 +332,7 @@ static void test_pkt_read_append(void)
/* Place the IP + UDP header in the first fragment */
if (!net_buf_tailroom(frag)) {
ipv6 = (struct ipv6_hdr *)(frag->data);
udp = (struct udp_hdr *)((void *)ipv6 + sizeof(*ipv6));
udp = (struct udp_hdr *)((u8_t *)ipv6 + sizeof(*ipv6));
if (net_buf_tailroom(frag) < sizeof(ipv6)) {
printk("Not enough space for IPv6 header, "
"needed %zd bytes, has %zd bytes\n",
@ -348,7 +348,7 @@ static void test_pkt_read_append(void)
zassert_true(false, "No space for UDP header");
}
net_pkt_set_appdata(pkt, (void *)udp + sizeof(*udp));
net_pkt_set_appdata(pkt, (u8_t *)udp + sizeof(*udp));
net_pkt_set_appdatalen(pkt, 0);
}