global: prefer sizeof(*pointer) when possible
Suggested-by: Sultan Alsawaf <sultanxda@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
4d59d1f2c5
commit
17546fcd75
10
src/config.c
10
src/config.c
|
@ -310,7 +310,7 @@ static inline bool parse_allowedips(struct wgpeer *peer, struct wgallowedip **la
|
||||||
saved_entry = strdup(mask);
|
saved_entry = strdup(mask);
|
||||||
ip = strsep(&mask, "/");
|
ip = strsep(&mask, "/");
|
||||||
|
|
||||||
new_allowedip = calloc(1, sizeof(struct wgallowedip));
|
new_allowedip = calloc(1, sizeof(*new_allowedip));
|
||||||
if (!new_allowedip) {
|
if (!new_allowedip) {
|
||||||
perror("calloc");
|
perror("calloc");
|
||||||
free(saved_entry);
|
free(saved_entry);
|
||||||
|
@ -464,8 +464,8 @@ out:
|
||||||
|
|
||||||
bool config_read_init(struct config_ctx *ctx, bool append)
|
bool config_read_init(struct config_ctx *ctx, bool append)
|
||||||
{
|
{
|
||||||
memset(ctx, 0, sizeof(struct config_ctx));
|
memset(ctx, 0, sizeof(*ctx));
|
||||||
ctx->device = calloc(1, sizeof(struct wgdevice));
|
ctx->device = calloc(1, sizeof(*ctx->device));
|
||||||
if (!ctx->device) {
|
if (!ctx->device) {
|
||||||
perror("calloc");
|
perror("calloc");
|
||||||
return false;
|
return false;
|
||||||
|
@ -511,7 +511,7 @@ static char *strip_spaces(const char *in)
|
||||||
|
|
||||||
struct wgdevice *config_read_cmd(char *argv[], int argc)
|
struct wgdevice *config_read_cmd(char *argv[], int argc)
|
||||||
{
|
{
|
||||||
struct wgdevice *device = calloc(1, sizeof(struct wgdevice));
|
struct wgdevice *device = calloc(1, sizeof(*device));
|
||||||
struct wgpeer *peer = NULL;
|
struct wgpeer *peer = NULL;
|
||||||
struct wgallowedip *allowedip = NULL;
|
struct wgallowedip *allowedip = NULL;
|
||||||
|
|
||||||
|
@ -537,7 +537,7 @@ struct wgdevice *config_read_cmd(char *argv[], int argc)
|
||||||
argv += 2;
|
argv += 2;
|
||||||
argc -= 2;
|
argc -= 2;
|
||||||
} else if (!strcmp(argv[0], "peer") && argc >= 2) {
|
} else if (!strcmp(argv[0], "peer") && argc >= 2) {
|
||||||
struct wgpeer *new_peer = calloc(1, sizeof(struct wgpeer));
|
struct wgpeer *new_peer = calloc(1, sizeof(*new_peer));
|
||||||
|
|
||||||
allowedip = NULL;
|
allowedip = NULL;
|
||||||
if (!new_peer) {
|
if (!new_peer) {
|
||||||
|
|
12
src/ipc.c
12
src/ipc.c
|
@ -294,7 +294,7 @@ static int userspace_get_device(struct wgdevice **out, const char *interface)
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int ret = -EPROTO;
|
int ret = -EPROTO;
|
||||||
|
|
||||||
*out = dev = calloc(1, sizeof(struct wgdevice));
|
*out = dev = calloc(1, sizeof(*dev));
|
||||||
if (!dev)
|
if (!dev)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
|
@ -332,7 +332,7 @@ static int userspace_get_device(struct wgdevice **out, const char *interface)
|
||||||
dev->fwmark = NUM(0xffffffffU);
|
dev->fwmark = NUM(0xffffffffU);
|
||||||
dev->flags |= WGDEVICE_HAS_FWMARK;
|
dev->flags |= WGDEVICE_HAS_FWMARK;
|
||||||
} else if (!strcmp(key, "public_key")) {
|
} else if (!strcmp(key, "public_key")) {
|
||||||
struct wgpeer *new_peer = calloc(1, sizeof(struct wgpeer));
|
struct wgpeer *new_peer = calloc(1, sizeof(*new_peer));
|
||||||
|
|
||||||
if (!new_peer) {
|
if (!new_peer) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
|
@ -398,7 +398,7 @@ static int userspace_get_device(struct wgdevice **out, const char *interface)
|
||||||
|
|
||||||
if (!mask || !isdigit(mask[0]))
|
if (!mask || !isdigit(mask[0]))
|
||||||
break;
|
break;
|
||||||
new_allowedip = calloc(1, sizeof(struct wgallowedip));
|
new_allowedip = calloc(1, sizeof(*new_allowedip));
|
||||||
if (!new_allowedip) {
|
if (!new_allowedip) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto err;
|
goto err;
|
||||||
|
@ -708,7 +708,7 @@ static int parse_allowedip(const struct nlattr *attr, void *data)
|
||||||
static int parse_allowedips(const struct nlattr *attr, void *data)
|
static int parse_allowedips(const struct nlattr *attr, void *data)
|
||||||
{
|
{
|
||||||
struct wgpeer *peer = data;
|
struct wgpeer *peer = data;
|
||||||
struct wgallowedip *new_allowedip = calloc(1, sizeof(struct wgallowedip));
|
struct wgallowedip *new_allowedip = calloc(1, sizeof(*new_allowedip));
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!new_allowedip) {
|
if (!new_allowedip) {
|
||||||
|
@ -787,7 +787,7 @@ static int parse_peer(const struct nlattr *attr, void *data)
|
||||||
static int parse_peers(const struct nlattr *attr, void *data)
|
static int parse_peers(const struct nlattr *attr, void *data)
|
||||||
{
|
{
|
||||||
struct wgdevice *device = data;
|
struct wgdevice *device = data;
|
||||||
struct wgpeer *new_peer = calloc(1, sizeof(struct wgpeer));
|
struct wgpeer *new_peer = calloc(1, sizeof(*new_peer));
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!new_peer) {
|
if (!new_peer) {
|
||||||
|
@ -886,7 +886,7 @@ static int kernel_get_device(struct wgdevice **device, const char *interface)
|
||||||
struct mnlg_socket *nlg;
|
struct mnlg_socket *nlg;
|
||||||
|
|
||||||
try_again:
|
try_again:
|
||||||
*device = calloc(1, sizeof(struct wgdevice));
|
*device = calloc(1, sizeof(**device));
|
||||||
if (!*device)
|
if (!*device)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
|
|
|
@ -53,12 +53,12 @@ static void sort_peers(struct wgdevice *device)
|
||||||
++peer_count;
|
++peer_count;
|
||||||
if (!peer_count)
|
if (!peer_count)
|
||||||
return;
|
return;
|
||||||
peers = calloc(peer_count, sizeof(struct wgpeer *));
|
peers = calloc(peer_count, sizeof(*peers));
|
||||||
if (!peers)
|
if (!peers)
|
||||||
return;
|
return;
|
||||||
for_each_wgpeer(device, peer)
|
for_each_wgpeer(device, peer)
|
||||||
peers[i++] = peer;
|
peers[i++] = peer;
|
||||||
qsort(peers, peer_count, sizeof(struct wgpeer *), peer_cmp);
|
qsort(peers, peer_count, sizeof(*peers), peer_cmp);
|
||||||
device->first_peer = peers[0];
|
device->first_peer = peers[0];
|
||||||
peers[0]->next_peer = NULL;
|
peers[0]->next_peer = NULL;
|
||||||
for (i = 1; i < peer_count; ++i) {
|
for (i = 1; i < peer_count; ++i) {
|
||||||
|
|
Loading…
Reference in New Issue