]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Replace many memset by initialisation inline at the declaration moment
authorBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 2 Mar 2023 09:00:48 +0000 (10:00 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 2 Mar 2023 09:00:48 +0000 (10:00 +0100)
While here, remove GNU extension only initialisation.

src/init_sockfd.c
src/mlmmj-bounce.c
src/mlmmj-send.c
src/send_help.c
src/subscriberfuncs.c
tests/fakesmtpd.c
tests/mlmmj.c
tests/mlmmj_tests.c

index babfe3c59c96dacfb7cdacd5fc0d77818792f197..d019ee61101c32986330467df67fa60eeb1324bd 100644 (file)
 void init_sockfd(int *sockfd, const char *relayhost, unsigned short port)
 {
        int on, sd = -1;
-       struct addrinfo *ai = NULL, *curai, hints;
+       struct addrinfo *ai = NULL, *curai, hints = { 0 };
        char srv[NI_MAXSERV];
        *sockfd = -1;
 
-       memset(&hints, 0, sizeof(hints));
        hints.ai_socktype = SOCK_STREAM;
        hints.ai_family = PF_UNSPEC;
        snprintf(srv, sizeof(srv), "%d", port);
index fd223c4e78de1d32269370d8af70008ed80980a3..bcc17376925123b8b62aef5bd8b7a4b1d145da6d 100644 (file)
@@ -74,9 +74,8 @@ void do_probe(struct ml *ml, const char *addr)
        char *probefile;
        int fd;
        time_t t;
-       struct mail mail;
+       struct mail mail = { 0 };
 
-       memset(&mail, 0, sizeof(mail));
        myaddr = lowercase(addr);
 
        gen_addr_cookie(from, ml, "bounces-probe-", myaddr)
index d754b4986776e88f0a3cbc6a159e31f43b89646d..f15eb76aba8c40166040d312b2d6af4d446a0a9e 100644 (file)
@@ -429,11 +429,10 @@ int main(int argc, char **argv)
        strlist stl = tll_init();
        unsigned short smtpport;
        struct sigaction sigact;
-       struct mail mail;
+       struct mail mail = { 0 };
        struct ml ml;
        int subdirfd, mailfd;
 
-       memset(&mail, 0, sizeof(mail));
        log_set_name(argv[0]);
        ml_init(&ml);
 
index 5dee52d64797903592d839614ff5253e22c49f36..023aca9e2bccc03b3b4d39ee18b6e5ecabb267b7 100644 (file)
@@ -33,9 +33,8 @@ void
 send_help(struct ml *ml, const char *queuefilename, const char *emailaddr)
 {
        char *fromaddr;
-       struct mail mail;
+       struct mail mail = { 0 };
 
-       memset(&mail, 0, sizeof(mail));
        gen_addr(fromaddr, ml, "bounces-help");
 
        mail.to = emailaddr;
index 11359ec3f5433260faa0bd093be2cc1dcd43eccb..334172762478525b6901699e33852ea309c1202b 100644 (file)
@@ -243,9 +243,8 @@ generate_subconfirm(struct ml *ml, const char *subaddr, enum subtype typesub,
        char *randomstr = NULL, *confirmaddr;
        const char *tmpstr, *listtext;
        int fd = openat(ml->fd, sub ? "subconf" : "unsubconf", O_DIRECTORY|O_CLOEXEC);
-       struct mail mail;
+       struct mail mail = { 0 };
 
-       memset(&mail, 0, sizeof(mail));
        if (fd == -1) {
                log_error(LOG_ARGS, "Cound not open(%s/%s)", ml->dir,
                    sub ? "subconf" : "unsubconf");
index 824f1b06661727d5aec1e06c33413fd0bea35f72..90ec0d91a34dcf9ce69dd846a4a8d4707c3006ca 100644 (file)
@@ -53,7 +53,7 @@ main(void)
        int s, c;
        FILE *f;
        socklen_t clsize = 0;
-       struct sockaddr_in me, cl;
+       struct sockaddr_in me = { 0 }, cl;
        char *line = NULL;
        size_t linecap = 0;
        int mailnum = 0;
@@ -63,7 +63,6 @@ main(void)
                exit(1);
        if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &(int) { 1 }, sizeof(int)) != 0)
                exit(2);
-       memset(&me, 0, sizeof(me));
        me.sin_family = AF_INET;
        me.sin_addr.s_addr = inet_addr("127.0.0.1");
        /* specific interface */
index 5ac410bf7906819cf10ff51086cbef65135850d9..ca2a332845fb7b0a78ec2bc36ff0b55297da309f 100644 (file)
@@ -1114,7 +1114,7 @@ ATF_TC_BODY(do_bouncemail, tc)
 
 ATF_TC_BODY(send_mail_basics, tc)
 {
-       struct mail mail = {};
+       struct mail mail = { 0 };
        ATF_REQUIRE_EQ_MSG(send_mail(1, &mail, -1, -1, false), 0, "Failure with to == NULL");
        mail.to = "plop";
        ATF_REQUIRE_EQ_MSG(send_mail(1, &mail, -1, -1, false), 0, "Failure with to without @");
@@ -1125,7 +1125,7 @@ ATF_TC_BODY(send_mail_basics, tc)
 ATF_TC_BODY(send_mail, tc)
 {
        int smtppipe[2];
-       struct mail mail = {};
+       struct mail mail = { 0 };
        ATF_REQUIRE(socketpair(AF_UNIX, SOCK_STREAM, 0, smtppipe) >= 0);
        pid_t p = atf_utils_fork();
        if (p == 0) {
@@ -2029,7 +2029,7 @@ ATF_TC_BODY(newsmtp, tc)
 
 ATF_TC_BODY(save_queue, tc)
 {
-       struct mail mail = {};
+       struct mail mail = { 0 };
        mail.to = "plop";
        mail.from = "bla";
 
@@ -2083,7 +2083,7 @@ ATF_TC_BODY(send_single_mail, tc)
        struct ml ml;
        ml_init(&ml);
        ml.dir = "list";
-       struct mail mail = {};
+       struct mail mail = { 0 };
        ATF_REQUIRE_MSG(ml_open(&ml, false), "impossible to open the mailing list");
        atf_utils_create_file("list/control/smtpport", "25678");
        int smtppipe[2];
index 5bef57eb29491c52ec3ac1d1d4c132947c846553..34c6c6ceb8e78b2f73dddae73aac0e6907d072a3 100644 (file)
@@ -71,13 +71,12 @@ int
 fakesmtp(int pipe)
 {
        int s;
-       struct sockaddr_in me;
+       struct sockaddr_in me = { 0 };
        s = socket(AF_INET, SOCK_STREAM, 0);
        if (s < 0)
                exit(1);
        if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &(int) { 1 }, sizeof(int)) != 0)
                exit(2);
-       memset(&me, 0, sizeof(me));
        me.sin_family = AF_INET;
        me.sin_addr.s_addr = inet_addr("127.0.0.1");
        /* specific interface */