From 5b07039b0712bee0f19749d63116a10fb08a2d8b Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Wed, 1 May 2013 17:31:33 +0200 Subject: [PATCH] Rename xmalloc_and_zero() to xzalloc(). The former name is more or less only used by tinc, the latter is used by other projects as well, and shorter as well. --- src/conf.c | 2 +- src/connection.c | 2 +- src/edge.c | 2 +- src/fake-getaddrinfo.c | 2 +- src/hash.c | 6 +++--- src/list.c | 4 ++-- src/net.c | 2 +- src/net_socket.c | 2 +- src/node.c | 4 ++-- src/openssl/cipher.c | 4 ++-- src/openssl/digest.c | 2 +- src/splay_tree.c | 4 ++-- src/subnet.c | 2 +- src/tincctl.c | 2 +- src/top.c | 4 ++-- src/xalloc.h | 4 ++-- 16 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/conf.c b/src/conf.c index c4f8abb..71e4509 100644 --- a/src/conf.c +++ b/src/conf.c @@ -71,7 +71,7 @@ void exit_configuration(splay_tree_t ** config_tree) { } config_t *new_config(void) { - return xmalloc_and_zero(sizeof(config_t)); + return xzalloc(sizeof(config_t)); } void free_config(config_t *cfg) { diff --git a/src/connection.c b/src/connection.c index 9c45978..496f674 100644 --- a/src/connection.c +++ b/src/connection.c @@ -48,7 +48,7 @@ void exit_connections(void) { } connection_t *new_connection(void) { - return xmalloc_and_zero(sizeof(connection_t)); + return xzalloc(sizeof(connection_t)); } void free_connection(connection_t *c) { diff --git a/src/edge.c b/src/edge.c index fd03327..b34fdc2 100644 --- a/src/edge.c +++ b/src/edge.c @@ -70,7 +70,7 @@ void exit_edges(void) { /* Creation and deletion of connection elements */ edge_t *new_edge(void) { - return xmalloc_and_zero(sizeof(edge_t)); + return xzalloc(sizeof(edge_t)); } void free_edge(edge_t *e) { diff --git a/src/fake-getaddrinfo.c b/src/fake-getaddrinfo.c index db50f73..cb821b5 100644 --- a/src/fake-getaddrinfo.c +++ b/src/fake-getaddrinfo.c @@ -48,7 +48,7 @@ void freeaddrinfo(struct addrinfo *ai) { static struct addrinfo *malloc_ai(uint16_t port, uint32_t addr) { struct addrinfo *ai; - ai = xmalloc_and_zero(sizeof(struct addrinfo) + sizeof(struct sockaddr_in)); + ai = xzalloc(sizeof(struct addrinfo) + sizeof(struct sockaddr_in)); ai->ai_addr = (struct sockaddr *)(ai + 1); ai->ai_addrlen = sizeof(struct sockaddr_in); diff --git a/src/hash.c b/src/hash.c index 1d203c5..36b510c 100644 --- a/src/hash.c +++ b/src/hash.c @@ -52,11 +52,11 @@ static uint32_t modulo(uint32_t hash, size_t n) { /* (De)allocation */ hash_t *hash_alloc(size_t n, size_t size) { - hash_t *hash = xmalloc_and_zero(sizeof *hash); + hash_t *hash = xzalloc(sizeof *hash); hash->n = n; hash->size = size; - hash->keys = xmalloc_and_zero(hash->n * hash->size); - hash->values = xmalloc_and_zero(hash->n * sizeof *hash->values); + hash->keys = xzalloc(hash->n * hash->size); + hash->values = xzalloc(hash->n * sizeof *hash->values); return hash; } diff --git a/src/list.c b/src/list.c index 2dd414a..e2eeabc 100644 --- a/src/list.c +++ b/src/list.c @@ -26,7 +26,7 @@ /* (De)constructors */ list_t *list_alloc(list_action_t delete) { - list_t *list = xmalloc_and_zero(sizeof(list_t)); + list_t *list = xzalloc(sizeof(list_t)); list->delete = delete; return list; @@ -37,7 +37,7 @@ void list_free(list_t *list) { } list_node_t *list_alloc_node(void) { - return xmalloc_and_zero(sizeof(list_node_t)); + return xzalloc(sizeof(list_node_t)); } void list_free_node(list_t *list, list_node_t *node) { diff --git a/src/net.c b/src/net.c index 1487e81..d2eacf3 100644 --- a/src/net.c +++ b/src/net.c @@ -224,7 +224,7 @@ static void periodic_handler(void *data) { if(!found) { logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name); - outgoing_t *outgoing = xmalloc_and_zero(sizeof *outgoing); + outgoing_t *outgoing = xzalloc(sizeof *outgoing); outgoing->name = xstrdup(n->name); list_insert_tail(outgoing_list, outgoing); setup_outgoing_connection(outgoing); diff --git a/src/net_socket.c b/src/net_socket.c index 5332ed2..1b49aee 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -674,7 +674,7 @@ void try_outgoing_connections(void) { } if(!found) { - outgoing_t *outgoing = xmalloc_and_zero(sizeof *outgoing); + outgoing_t *outgoing = xzalloc(sizeof *outgoing); outgoing->name = name; list_insert_tail(outgoing_list, outgoing); setup_outgoing_connection(outgoing); diff --git a/src/node.c b/src/node.c index 2f51744..aab83ca 100644 --- a/src/node.c +++ b/src/node.c @@ -50,9 +50,9 @@ void exit_nodes(void) { } node_t *new_node(void) { - node_t *n = xmalloc_and_zero(sizeof *n); + node_t *n = xzalloc(sizeof *n); - if(replaywin) n->late = xmalloc_and_zero(replaywin); + if(replaywin) n->late = xzalloc(replaywin); n->subnet_tree = new_subnet_tree(); n->edge_tree = new_edge_tree(); n->mtu = MTU; diff --git a/src/openssl/cipher.c b/src/openssl/cipher.c index 32cb5ce..7f73cb1 100644 --- a/src/openssl/cipher.c +++ b/src/openssl/cipher.c @@ -40,7 +40,7 @@ typedef struct cipher_counter { } cipher_counter_t; static cipher_t *cipher_open(const EVP_CIPHER *evp_cipher) { - cipher_t *cipher = xmalloc_and_zero(sizeof *cipher); + cipher_t *cipher = xzalloc(sizeof *cipher); cipher->cipher = evp_cipher; EVP_CIPHER_CTX_init(&cipher->ctx); @@ -135,7 +135,7 @@ bool cipher_set_counter_key(cipher_t *cipher, void *key) { } if(!cipher->counter) - cipher->counter = xmalloc_and_zero(sizeof *cipher->counter); + cipher->counter = xzalloc(sizeof *cipher->counter); else cipher->counter->n = 0; diff --git a/src/openssl/digest.c b/src/openssl/digest.c index 9406701..9699d37 100644 --- a/src/openssl/digest.c +++ b/src/openssl/digest.c @@ -29,7 +29,7 @@ #include "../logger.h" static digest_t *digest_open(const EVP_MD *evp_md, int maclength) { - digest_t *digest = xmalloc_and_zero(sizeof *digest); + digest_t *digest = xzalloc(sizeof *digest); digest->digest = evp_md; int digestlen = EVP_MD_size(digest->digest); diff --git a/src/splay_tree.c b/src/splay_tree.c index 54a46f2..6b5b56f 100644 --- a/src/splay_tree.c +++ b/src/splay_tree.c @@ -238,7 +238,7 @@ static void splay_bottom_up(splay_tree_t *tree, splay_node_t *node) { splay_tree_t *splay_alloc_tree(splay_compare_t compare, splay_action_t delete) { splay_tree_t *tree; - tree = xmalloc_and_zero(sizeof(splay_tree_t)); + tree = xzalloc(sizeof(splay_tree_t)); tree->compare = compare; tree->delete = delete; @@ -250,7 +250,7 @@ void splay_free_tree(splay_tree_t *tree) { } splay_node_t *splay_alloc_node(void) { - return xmalloc_and_zero(sizeof(splay_node_t)); + return xzalloc(sizeof(splay_node_t)); } void splay_free_node(splay_tree_t *tree, splay_node_t *node) { diff --git a/src/subnet.c b/src/subnet.c index 12ca03c..bf4300e 100644 --- a/src/subnet.c +++ b/src/subnet.c @@ -79,7 +79,7 @@ void free_subnet_tree(splay_tree_t *subnet_tree) { /* Allocating and freeing space for subnets */ subnet_t *new_subnet(void) { - return xmalloc_and_zero(sizeof(subnet_t)); + return xzalloc(sizeof(subnet_t)); } void free_subnet(subnet_t *subnet) { diff --git a/src/tincctl.c b/src/tincctl.c index a8930fe..331299a 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -792,7 +792,7 @@ static int cmd_start(int argc, char *argv[]) { c = "tincd"; int nargc = 0; - char **nargv = xmalloc_and_zero((optind + argc) * sizeof *nargv); + char **nargv = xzalloc((optind + argc) * sizeof *nargv); nargv[nargc++] = c; for(int i = 1; i < optind; i++) diff --git a/src/top.c b/src/top.c index 703391c..b1ab40c 100644 --- a/src/top.c +++ b/src/top.c @@ -108,7 +108,7 @@ static void update(int fd) { found = ns; break; } else { - found = xmalloc_and_zero(sizeof *found); + found = xzalloc(sizeof *found); found->name = xstrdup(name); list_insert_before(&node_list, node, found); changed = true; @@ -117,7 +117,7 @@ static void update(int fd) { } if(!found) { - found = xmalloc_and_zero(sizeof *found); + found = xzalloc(sizeof *found); found->name = xstrdup(name); list_insert_tail(&node_list, found); changed = true; diff --git a/src/xalloc.h b/src/xalloc.h index 42d0d95..397f7b0 100644 --- a/src/xalloc.h +++ b/src/xalloc.h @@ -1,7 +1,7 @@ /* xalloc.h -- malloc and related fuctions with out of memory checking Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc. - Copyright (C) 2011 Guus Sliepen + Copyright (C) 2011-2013 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,7 +27,7 @@ static inline void *xmalloc(size_t n) { return p; } -static inline void *xmalloc_and_zero(size_t n) { +static inline void *xzalloc(size_t n) { void *p = calloc(1, n); if(!p) abort(); -- 2.25.1