Use Memory_safeCalloc() to allocate zeroed memory.
authorTilman Sauerbeck <tilman@code-monkey.de>
Wed, 27 Dec 2017 15:11:08 +0000 (16:11 +0100)
committerTilman Sauerbeck <tilman@code-monkey.de>
Wed, 27 Dec 2017 15:11:08 +0000 (16:11 +0100)
This replaces a few occurences of Memory_safeMalloc() followed by
memset(ptr, 0, ...) with calls to Memory_safeCalloc().

src/ban.c
src/channel.c
src/client.c
src/messages.c

index 7028ea6f5dd597bd60f3c3e27d7293202d87e3f8..84e95dc174e7a3ed881b616a70f4a75d39f573b6 100644 (file)
--- a/src/ban.c
+++ b/src/ban.c
@@ -351,8 +351,7 @@ static void Ban_readBanFile(void)
                if (p == NULL) break;
                reason = p;
 
-               ban = Memory_safeMalloc(1, sizeof(ban_t));
-               memset(ban, 0, sizeof(ban_t));
+               ban = Memory_safeCalloc(1, sizeof(ban_t));
                SSLi_hex2hash(hexhash, ban->hash);
                if (inet_pton(AF_INET, address, &ban->address) == 0) {
                        if (inet_pton(AF_INET6, address, &ban->address) == 0) {
index da15a52f175e602bc3c0a633b472862f4684e013..346ea44ddfd9699f19da2181b77de2b85aefeab1 100644 (file)
@@ -47,8 +47,7 @@ static channel_t *createChannel(int id, const char *name, const char *desc)
 {
        channel_t *ch;
 
-       ch = Memory_safeMalloc(1, sizeof(channel_t));
-       memset(ch, 0, sizeof(channel_t));
+       ch = Memory_safeCalloc(1, sizeof(channel_t));
        ch->id = id;
        ch->name = strdup(name);
        if (desc)
index 579a1b66ed1f694223f4805cbd897e4cc99791ac..80cbe3d67802e850d68b7a9d2d570ac3976d8c8f 100644 (file)
@@ -224,8 +224,7 @@ void recheckCodecVersions(client_t *connectingClient)
                                }
                        }
                        if (!found) {
-                               cd = Memory_safeMalloc(1, sizeof(codec_t));
-                               memset(cd, 0, sizeof(codec_t));
+                               cd = Memory_safeCalloc(1, sizeof(codec_t));
                                init_list_entry(&cd->node);
                                cd->codec = codec_itr->codec;
                                cd->count = 1;
index d661c9e356e674cdc1a69592179131c82b847ee6..d99548563c042cb04e417930ece49d2a6cc9db59 100644 (file)
@@ -267,9 +267,8 @@ int Msg_messageToNetwork(message_t *msg, uint8_t *buffer)
 
 static message_t *Msg_create_nopayload(messageType_t messageType)
 {
-       message_t *msg = Memory_safeMalloc(1, sizeof(message_t));
+       message_t *msg = Memory_safeCalloc(1, sizeof(message_t));
 
-       memset(msg, 0, sizeof(message_t));
        msg->refcount = 1;
        msg->messageType = messageType;
        init_list_entry(&msg->node);
@@ -382,14 +381,12 @@ message_t *Msg_banList_create(int n_bans)
        message_t *msg = Msg_create_nopayload(BanList);
        int i;
 
-       msg->payload.banList = Memory_safeMalloc(1, sizeof(MumbleProto__BanList));
-       memset(msg->payload.banList, 0, sizeof(MumbleProto__BanList));
+       msg->payload.banList = Memory_safeCalloc(1, sizeof(MumbleProto__BanList));
        mumble_proto__ban_list__init(msg->payload.banList);
        msg->payload.banList->n_bans = n_bans;
        msg->payload.banList->bans = Memory_safeMalloc(1, sizeof(MumbleProto__BanList__BanEntry *) * n_bans);
        for (i = 0; i < n_bans; i++) {
-               msg->payload.banList->bans[i] = Memory_safeMalloc(1, sizeof(MumbleProto__BanList__BanEntry));
-               memset(msg->payload.banList->bans[i], 0, sizeof(MumbleProto__BanList__BanEntry));
+               msg->payload.banList->bans[i] = Memory_safeCalloc(1, sizeof(MumbleProto__BanList__BanEntry));
                mumble_proto__ban_list__ban_entry__init(msg->payload.banList->bans[i]);
        }
        return msg;