Skip to content

Commit fe4cc83

Browse files
committed
Add parens to sizeof operator to clarify usage
Convert sizeof *ptr -> sizeof(*ptr) to avoid confusion. This is in response to the (false) bug report 2568. Signed-off-by: Sean Hefty <[email protected]>
1 parent 2b12e34 commit fe4cc83

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

src/acm.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ static int ucma_ib_set_addr(struct rdma_addrinfo *ib_rai,
176176
struct sockaddr_ib *src, *dst;
177177
struct ibv_path_record *path;
178178

179-
src = calloc(1, sizeof *src);
179+
src = calloc(1, sizeof(*src));
180180
if (!src)
181181
return ERR(ENOMEM);
182182

183-
dst = calloc(1, sizeof *dst);
183+
dst = calloc(1, sizeof(*dst));
184184
if (!dst) {
185185
free(src);
186186
return ERR(ENOMEM);
@@ -217,7 +217,7 @@ static int ucma_ib_set_connect(struct rdma_addrinfo *ib_rai,
217217
if (rai->ai_family == AF_IB)
218218
return 0;
219219

220-
hdr = calloc(1, sizeof *hdr);
220+
hdr = calloc(1, sizeof(*hdr));
221221
if (!hdr)
222222
return ERR(ENOMEM);
223223

src/addrinfo.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct rdma_addrinfo nohints;
4949

5050
static void ucma_convert_to_ai(struct addrinfo *ai, struct rdma_addrinfo *rai)
5151
{
52-
memset(ai, 0, sizeof *ai);
52+
memset(ai, 0, sizeof(*ai));
5353
if (rai->ai_flags & RAI_PASSIVE)
5454
ai->ai_flags = AI_PASSIVE;
5555
if (rai->ai_flags & RAI_NUMERICHOST)

src/cma.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ int ucma_init(void)
241241
goto err2;
242242
}
243243

244-
cma_dev_array = calloc(dev_cnt, sizeof *cma_dev_array);
244+
cma_dev_array = calloc(dev_cnt, sizeof(*cma_dev_array));
245245
if (!cma_dev_array) {
246246
ret = ERR(ENOMEM);
247247
goto err2;
@@ -305,7 +305,7 @@ static int ucma_init_device(struct cma_device *cma_dev)
305305
goto err;
306306
}
307307

308-
cma_dev->port = malloc(sizeof *cma_dev->port * attr.phys_port_cnt);
308+
cma_dev->port = malloc(sizeof(*cma_dev->port) * attr.phys_port_cnt);
309309
if (!cma_dev->port) {
310310
ret = ERR(ENOMEM);
311311
goto err;
@@ -362,7 +362,7 @@ struct ibv_context **rdma_get_devices(int *num_devices)
362362
if (ucma_init_all())
363363
goto out;
364364

365-
devs = malloc(sizeof *devs * (cma_dev_cnt + 1));
365+
devs = malloc(sizeof(*devs) * (cma_dev_cnt + 1));
366366
if (!devs)
367367
goto out;
368368

@@ -392,7 +392,7 @@ struct rdma_event_channel *rdma_create_event_channel(void)
392392
if (ucma_init())
393393
return NULL;
394394

395-
channel = malloc(sizeof *channel);
395+
channel = malloc(sizeof(*channel));
396396
if (!channel)
397397
return NULL;
398398

@@ -514,7 +514,7 @@ static struct cma_id_private *ucma_alloc_id(struct rdma_event_channel *channel,
514514
{
515515
struct cma_id_private *id_priv;
516516

517-
id_priv = calloc(1, sizeof *id_priv);
517+
id_priv = calloc(1, sizeof(*id_priv));
518518
if (!id_priv)
519519
return NULL;
520520

@@ -791,7 +791,7 @@ static int ucma_query_route(struct rdma_cm_id *id)
791791
VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp);
792792

793793
if (resp.num_paths) {
794-
id->route.path_rec = malloc(sizeof *id->route.path_rec *
794+
id->route.path_rec = malloc(sizeof(*id->route.path_rec) *
795795
resp.num_paths);
796796
if (!id->route.path_rec)
797797
return ERR(ENOMEM);
@@ -1333,7 +1333,7 @@ int rdma_create_srq(struct rdma_cm_id *id, struct ibv_pd *pd,
13331333
struct ibv_srq_init_attr_ex attr_ex;
13341334
int ret;
13351335

1336-
memcpy(&attr_ex, attr, sizeof *attr);
1336+
memcpy(&attr_ex, attr, sizeof(*attr));
13371337
attr_ex.comp_mask = IBV_SRQ_INIT_ATTR_TYPE | IBV_SRQ_INIT_ATTR_PD;
13381338
if (id->qp_type == IBV_QPT_XRC_RECV) {
13391339
attr_ex.srq_type = IBV_SRQT_XRC;
@@ -1342,7 +1342,7 @@ int rdma_create_srq(struct rdma_cm_id *id, struct ibv_pd *pd,
13421342
}
13431343
attr_ex.pd = pd;
13441344
ret = rdma_create_srq_ex(id, &attr_ex);
1345-
memcpy(attr, &attr_ex, sizeof *attr);
1345+
memcpy(attr, &attr_ex, sizeof(*attr));
13461346
return ret;
13471347
}
13481348

@@ -1423,11 +1423,11 @@ int rdma_create_qp(struct rdma_cm_id *id, struct ibv_pd *pd,
14231423
struct ibv_qp_init_attr_ex attr_ex;
14241424
int ret;
14251425

1426-
memcpy(&attr_ex, qp_init_attr, sizeof *qp_init_attr);
1426+
memcpy(&attr_ex, qp_init_attr, sizeof(*qp_init_attr));
14271427
attr_ex.comp_mask = IBV_QP_INIT_ATTR_PD;
14281428
attr_ex.pd = pd ? pd : id->pd;
14291429
ret = rdma_create_qp_ex(id, &attr_ex);
1430-
memcpy(qp_init_attr, &attr_ex, sizeof *qp_init_attr);
1430+
memcpy(qp_init_attr, &attr_ex, sizeof(*qp_init_attr));
14311431
return ret;
14321432
}
14331433

@@ -1751,7 +1751,7 @@ static int rdma_join_multicast2(struct rdma_cm_id *id, struct sockaddr *addr,
17511751
int ret;
17521752

17531753
id_priv = container_of(id, struct cma_id_private, id);
1754-
mc = calloc(1, sizeof *mc);
1754+
mc = calloc(1, sizeof(*mc));
17551755
if (!mc)
17561756
return ERR(ENOMEM);
17571757

@@ -2096,12 +2096,12 @@ int rdma_get_cm_event(struct rdma_event_channel *channel,
20962096
if (!event)
20972097
return ERR(EINVAL);
20982098

2099-
evt = malloc(sizeof *evt);
2099+
evt = malloc(sizeof(*evt));
21002100
if (!evt)
21012101
return ERR(ENOMEM);
21022102

21032103
retry:
2104-
memset(evt, 0, sizeof *evt);
2104+
memset(evt, 0, sizeof(*evt));
21052105
CMA_INIT_CMD_RESP(&cmd, sizeof cmd, GET_EVENT, &resp, sizeof resp);
21062106
ret = write(channel->fd, &cmd, sizeof cmd);
21072107
if (ret != sizeof cmd) {
@@ -2354,7 +2354,7 @@ static int ucma_passive_ep(struct rdma_cm_id *id, struct rdma_addrinfo *res,
23542354
id->pd = pd;
23552355

23562356
if (qp_init_attr) {
2357-
id_priv->qp_init_attr = malloc(sizeof *qp_init_attr);
2357+
id_priv->qp_init_attr = malloc(sizeof(*qp_init_attr));
23582358
if (!id_priv->qp_init_attr)
23592359
return ERR(ENOMEM);
23602360

src/preload.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ static int fd_open(void)
260260
struct fd_info *fdi;
261261
int ret, index;
262262

263-
fdi = calloc(1, sizeof *fdi);
263+
fdi = calloc(1, sizeof(*fdi));
264264
if (!fdi)
265265
return ERR(ENOMEM);
266266

@@ -876,7 +876,7 @@ static struct pollfd *fds_alloc(nfds_t nfds)
876876
if (rfds)
877877
free(rfds);
878878

879-
rfds = malloc(sizeof *rfds * nfds);
879+
rfds = malloc(sizeof(*rfds) * nfds);
880880
rnfds = rfds ? nfds : 0;
881881
}
882882

@@ -1132,7 +1132,7 @@ int dup2(int oldfd, int newfd)
11321132
if (!oldfdi || ret != newfd)
11331133
return ret;
11341134

1135-
newfdi = calloc(1, sizeof *newfdi);
1135+
newfdi = calloc(1, sizeof(*newfdi));
11361136
if (!newfdi) {
11371137
close(newfd);
11381138
return ERR(ENOMEM);

src/rsocket.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ static struct rsocket *rs_alloc(struct rsocket *inherited_rs, int type)
568568
{
569569
struct rsocket *rs;
570570

571-
rs = calloc(1, sizeof *rs);
571+
rs = calloc(1, sizeof(*rs));
572572
if (!rs)
573573
return NULL;
574574

@@ -1396,7 +1396,7 @@ static int ds_get_src_addr(struct rsocket *rs,
13961396
int sock, ret;
13971397
uint16_t port;
13981398

1399-
*src_len = sizeof *src_addr;
1399+
*src_len = sizeof(*src_addr);
14001400
ret = getsockname(rs->udp_sock, &src_addr->sa, src_len);
14011401
if (ret || !rs_any_addr(src_addr))
14021402
return ret;
@@ -1410,7 +1410,7 @@ static int ds_get_src_addr(struct rsocket *rs,
14101410
if (ret)
14111411
goto out;
14121412

1413-
*src_len = sizeof *src_addr;
1413+
*src_len = sizeof(*src_addr);
14141414
ret = getsockname(sock, &src_addr->sa, src_len);
14151415
src_addr->sin.sin_port = port;
14161416
out:
@@ -2600,7 +2600,7 @@ static ssize_t ds_sendv_udp(struct rsocket *rs, const struct iovec *iov,
26002600
miov[0].iov_base = &hdr;
26012601
miov[0].iov_len = hdr.length;
26022602
if (iov && iovcnt)
2603-
memcpy(&miov[1], iov, sizeof *iov * iovcnt);
2603+
memcpy(&miov[1], iov, sizeof(*iov) * iovcnt);
26042604

26052605
memset(&msg, 0, sizeof msg);
26062606
msg.msg_name = &rs->conn_dest->addr;
@@ -2910,7 +2910,7 @@ static struct pollfd *rs_fds_alloc(nfds_t nfds)
29102910
if (rfds)
29112911
free(rfds);
29122912

2913-
rfds = malloc(sizeof *rfds * nfds);
2913+
rfds = malloc(sizeof(*rfds) * nfds);
29142914
rnfds = rfds ? nfds : 0;
29152915
}
29162916

@@ -3110,7 +3110,7 @@ rs_select_to_poll(int *nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfd
31103110
struct pollfd *fds;
31113111
int fd, i = 0;
31123112

3113-
fds = calloc(*nfds, sizeof *fds);
3113+
fds = calloc(*nfds, sizeof(*fds));
31143114
if (!fds)
31153115
return NULL;
31163116

@@ -3754,7 +3754,7 @@ off_t riomap(int socket, void *buf, size_t len, int prot, int flags, off_t offse
37543754
iomr = rs_get_iomap_mr(rs);
37553755
access |= IBV_ACCESS_REMOTE_WRITE;
37563756
} else {
3757-
iomr = calloc(1, sizeof *iomr);
3757+
iomr = calloc(1, sizeof(*iomr));
37583758
iomr->index = -1;
37593759
}
37603760
if (!iomr) {

0 commit comments

Comments
 (0)