From: Baptiste Daroussin Date: Thu, 2 Mar 2023 09:00:48 +0000 (+0100) Subject: Replace many memset by initialisation inline at the declaration moment X-Git-Tag: RELEASE_1_4_0b1~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b218a6c074d39f6c26fa82ec81a98cc34a9a940;p=thirdparty%2Fmlmmj.git Replace many memset by initialisation inline at the declaration moment While here, remove GNU extension only initialisation. --- diff --git a/src/init_sockfd.c b/src/init_sockfd.c index babfe3c5..d019ee61 100644 --- a/src/init_sockfd.c +++ b/src/init_sockfd.c @@ -38,11 +38,10 @@ 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); diff --git a/src/mlmmj-bounce.c b/src/mlmmj-bounce.c index fd223c4e..bcc17376 100644 --- a/src/mlmmj-bounce.c +++ b/src/mlmmj-bounce.c @@ -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) diff --git a/src/mlmmj-send.c b/src/mlmmj-send.c index d754b498..f15eb76a 100644 --- a/src/mlmmj-send.c +++ b/src/mlmmj-send.c @@ -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); diff --git a/src/send_help.c b/src/send_help.c index 5dee52d6..023aca9e 100644 --- a/src/send_help.c +++ b/src/send_help.c @@ -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; diff --git a/src/subscriberfuncs.c b/src/subscriberfuncs.c index 11359ec3..33417276 100644 --- a/src/subscriberfuncs.c +++ b/src/subscriberfuncs.c @@ -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"); diff --git a/tests/fakesmtpd.c b/tests/fakesmtpd.c index 824f1b06..90ec0d91 100644 --- a/tests/fakesmtpd.c +++ b/tests/fakesmtpd.c @@ -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 */ diff --git a/tests/mlmmj.c b/tests/mlmmj.c index 5ac410bf..ca2a3328 100644 --- a/tests/mlmmj.c +++ b/tests/mlmmj.c @@ -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]; diff --git a/tests/mlmmj_tests.c b/tests/mlmmj_tests.c index 5bef57eb..34c6c6ce 100644 --- a/tests/mlmmj_tests.c +++ b/tests/mlmmj_tests.c @@ -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 */