Replace memset 0 with initializers.

Test: Compiles and bionic unit tests pass.
Change-Id: I94e178c56d958beeb1c484e4d52d61df022189e8
diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp
index cb96f9f..7b64fbf 100644
--- a/tests/fortify_test.cpp
+++ b/tests/fortify_test.cpp
@@ -58,8 +58,7 @@
 }
 
 TEST_F(DEATHTEST, stpncpy2_fortified2) {
-  foo myfoo;
-  memset(&myfoo, 0, sizeof(myfoo));
+  foo myfoo = {};
   myfoo.one[0] = 'A'; // not null terminated string
   ASSERT_FORTIFY(stpncpy(myfoo.b, myfoo.one, sizeof(myfoo.b)));
 }
@@ -71,8 +70,7 @@
 }
 
 TEST_F(DEATHTEST, strncpy2_fortified2) {
-  foo myfoo;
-  memset(&myfoo, 0, sizeof(myfoo));
+  foo myfoo = {};
   myfoo.one[0] = 'A'; // not null terminated string
   ASSERT_FORTIFY(strncpy(myfoo.b, myfoo.one, sizeof(myfoo.b)));
 }
@@ -572,8 +570,7 @@
 
 TEST_F(DEATHTEST, FD_ISSET_fortified) {
 #if defined(__BIONIC__) // glibc catches this at compile-time.
-  fd_set set;
-  memset(&set, 0, sizeof(set));
+  fd_set set = {};
   ASSERT_FORTIFY(FD_ISSET(-1, &set));
 #endif
 }
diff --git a/tests/ifaddrs_test.cpp b/tests/ifaddrs_test.cpp
index da64770..01779f7 100644
--- a/tests/ifaddrs_test.cpp
+++ b/tests/ifaddrs_test.cpp
@@ -116,9 +116,7 @@
 
 static void CheckAddressIsInSet(const std::string& if_name, bool unicast,
                                 const std::set<in_addr_t>& addrs) {
-  ifreq ifr;
-  memset(&ifr, 0, sizeof(ifr));
-  ifr.ifr_addr.sa_family = AF_INET;
+  ifreq ifr = {.ifr_addr.sa_family = AF_INET};
   if_name.copy(ifr.ifr_name, IFNAMSIZ - 1);
 
   int fd = socket(AF_INET, SOCK_DGRAM, 0);
diff --git a/tests/netdb_test.cpp b/tests/netdb_test.cpp
index 1cb569c..f6e8a32 100644
--- a/tests/netdb_test.cpp
+++ b/tests/netdb_test.cpp
@@ -79,11 +79,7 @@
 }
 
 TEST(netdb, getaddrinfo_hints) {
-  addrinfo hints;
-  memset(&hints, 0, sizeof(hints));
-  hints.ai_family = AF_INET;
-  hints.ai_socktype = SOCK_STREAM;
-  hints.ai_protocol = IPPROTO_TCP;
+  addrinfo hints = {.ai_family = AF_INET, .ai_socktype = SOCK_STREAM, .ai_protocol = IPPROTO_TCP};
 
   addrinfo* ai = nullptr;
   ASSERT_EQ(0, getaddrinfo( "localhost", "9999", &hints, &ai));
@@ -113,8 +109,7 @@
 }
 
 TEST(netdb, getnameinfo_salen) {
-  sockaddr_storage ss;
-  memset(&ss, 0, sizeof(ss));
+  sockaddr_storage ss = {};
   sockaddr* sa = reinterpret_cast<sockaddr*>(&ss);
   char tmp[16];
 
@@ -142,11 +137,8 @@
 }
 
 TEST(netdb, getnameinfo_localhost) {
-  sockaddr_in addr;
   char host[NI_MAXHOST];
-  memset(&addr, 0, sizeof(sockaddr_in));
-  addr.sin_family = AF_INET;
-  addr.sin_addr.s_addr = htonl(0x7f000001);
+  sockaddr_in addr = {.sin_family = AF_INET, .sin_addr.s_addr = htonl(0x7f000001)};
   ASSERT_EQ(0, getnameinfo(reinterpret_cast<sockaddr*>(&addr), sizeof(addr),
                            host, sizeof(host), nullptr, 0, 0));
   ASSERT_STREQ(host, "localhost");
@@ -160,11 +152,8 @@
 }
 
 TEST(netdb, getnameinfo_ip6_localhost) {
-  sockaddr_in6 addr;
   char host[NI_MAXHOST];
-  memset(&addr, 0, sizeof(sockaddr_in6));
-  addr.sin6_family = AF_INET6;
-  addr.sin6_addr = in6addr_loopback;
+  sockaddr_in6 addr = {.sin6_family = AF_INET6, .sin6_addr = in6addr_loopback};
   ASSERT_EQ(0, getnameinfo(reinterpret_cast<sockaddr*>(&addr), sizeof(addr),
                            host, sizeof(host), nullptr, 0, 0));
   VerifyLocalhostName(host);
diff --git a/tests/netinet_ether_test.cpp b/tests/netinet_ether_test.cpp
index d7b81eb..a9de9bf 100644
--- a/tests/netinet_ether_test.cpp
+++ b/tests/netinet_ether_test.cpp
@@ -32,8 +32,7 @@
 }
 
 TEST(netinet_ether, ether_aton_r__ether_ntoa_r) {
-  ether_addr addr;
-  memset(&addr, 0, sizeof(addr));
+  ether_addr addr = {};
   ether_addr* a = ether_aton_r("12:34:56:78:9a:Bc", &addr);
   ASSERT_EQ(&addr, a);
   ASSERT_EQ(0x12, addr.ether_addr_octet[0]);
diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp
index c1719dc..f8bfcef 100644
--- a/tests/signal_test.cpp
+++ b/tests/signal_test.cpp
@@ -804,10 +804,7 @@
 
   ASSERT_EQ(0, sigaction(SIGUSR1, &handler, nullptr));
 
-  siginfo sent;
-  memset(&sent, 0, sizeof(sent));
-
-  sent.si_code = SI_TKILL;
+  siginfo sent = {.si_code = SI_TKILL};
   ASSERT_EQ(0, syscall(SYS_rt_tgsigqueueinfo, getpid(), gettid(), SIGUSR1, &sent))
     << "rt_tgsigqueueinfo failed: " << strerror(errno) << error_msg;
   ASSERT_EQ(sent.si_code, received.si_code) << "rt_tgsigqueueinfo modified si_code, expected "
diff --git a/tests/stack_unwinding_test.cpp b/tests/stack_unwinding_test.cpp
index 2f891a6..fc6c25c 100644
--- a/tests/stack_unwinding_test.cpp
+++ b/tests/stack_unwinding_test.cpp
@@ -43,8 +43,7 @@
   const char* symbol = "<unknown>";
   int offset = 0;
 
-  Dl_info info;
-  memset(&info, 0, sizeof(info));
+  Dl_info info = {};
   if (dladdr(ip, &info) != 0) {
     symbol = info.dli_sname;
     if (info.dli_saddr != nullptr) {
diff --git a/tests/sys_msg_test.cpp b/tests/sys_msg_test.cpp
index b2d855d..26e4559 100644
--- a/tests/sys_msg_test.cpp
+++ b/tests/sys_msg_test.cpp
@@ -45,8 +45,7 @@
   ASSERT_NE(id, -1);
 
   // Queue should be empty.
-  msqid_ds ds;
-  memset(&ds, 0, sizeof(ds));
+  msqid_ds ds = {};
   ASSERT_EQ(0, msgctl(id, IPC_STAT, &ds));
   ASSERT_EQ(0U, ds.msg_qnum);
   ASSERT_EQ(0U, ds.msg_cbytes);
@@ -64,7 +63,7 @@
   ASSERT_EQ(sizeof(msg.data), ds.msg_cbytes);
 
   // Read the message.
-  memset(&msg, 0, sizeof(msg));
+  msg = {};
   ASSERT_EQ(static_cast<ssize_t>(sizeof(msg.data)),
             msgrcv(id, &msg, sizeof(msg.data), 0, 0));
   ASSERT_EQ(1, msg.type);
diff --git a/tests/sys_procfs_test.cpp b/tests/sys_procfs_test.cpp
index 4a64742..d707c5d 100644
--- a/tests/sys_procfs_test.cpp
+++ b/tests/sys_procfs_test.cpp
@@ -20,20 +20,11 @@
 #include <sys/procfs.h>
 
 TEST(sys_procfs, types) {
-  elf_greg_t reg;
-  memset(&reg, 0, sizeof(reg));
-
-  elf_gregset_t regs;
-  memset(&regs, 0, sizeof(regs));
-
-  elf_fpregset_t fp_regs;
-  memset(&fp_regs, 0, sizeof(fp_regs));
-
-  prgregset_t pr_g_regs;
-  memset(&pr_g_regs, 0, sizeof(pr_g_regs));
-
-  prfpregset_t pr_fp_regs;
-  memset(&pr_fp_regs, 0, sizeof(pr_fp_regs));
+  elf_greg_t reg = {};
+  elf_gregset_t regs = {};
+  elf_fpregset_t fp_regs = {};
+  prgregset_t pr_g_regs = {};
+  prfpregset_t pr_fp_regs = {};
 
   static_assert(sizeof(prgregset_t) == sizeof(elf_gregset_t), "");
   static_assert(sizeof(prfpregset_t) == sizeof(elf_fpregset_t), "");
diff --git a/tests/sys_ptrace_test.cpp b/tests/sys_ptrace_test.cpp
index 499adbb..1f9c2a2 100644
--- a/tests/sys_ptrace_test.cpp
+++ b/tests/sys_ptrace_test.cpp
@@ -116,8 +116,7 @@
   ASSERT_EQ(0, ptrace(PTRACE_SETHBPREGS, child, -1, &address)) << strerror(errno);
   ASSERT_EQ(0, ptrace(PTRACE_SETHBPREGS, child, -2, &control)) << strerror(errno);
 #else // aarch64
-  user_hwdebug_state dreg_state;
-  memset(&dreg_state, 0, sizeof dreg_state);
+  user_hwdebug_state dreg_state = {};
   dreg_state.dbg_regs[0].addr = address;
   dreg_state.dbg_regs[0].ctrl = control;
 
@@ -304,8 +303,7 @@
   ASSERT_EQ(0, ptrace(PTRACE_SETHBPREGS, child, 1, &address)) << strerror(errno);
   ASSERT_EQ(0, ptrace(PTRACE_SETHBPREGS, child, 2, &control)) << strerror(errno);
 #else  // aarch64
-  user_hwdebug_state dreg_state;
-  memset(&dreg_state, 0, sizeof dreg_state);
+  user_hwdebug_state dreg_state = {};
   dreg_state.dbg_regs[0].addr = reinterpret_cast<uintptr_t>(address);
   dreg_state.dbg_regs[0].ctrl = control;
 
diff --git a/tests/sys_sem_test.cpp b/tests/sys_sem_test.cpp
index 27943cf..0b7a7ff 100644
--- a/tests/sys_sem_test.cpp
+++ b/tests/sys_sem_test.cpp
@@ -47,8 +47,7 @@
   ASSERT_NE(id, -1);
 
   // Check semaphore info.
-  semid_ds ds;
-  memset(&ds, 0, sizeof(ds));
+  semid_ds ds = {};
   ASSERT_EQ(0, semctl(id, 0, IPC_STAT, &ds));
   ASSERT_EQ(1U, ds.sem_nsems);
 
diff --git a/tests/sys_shm_test.cpp b/tests/sys_shm_test.cpp
index 65f9eba..74d13b5 100644
--- a/tests/sys_shm_test.cpp
+++ b/tests/sys_shm_test.cpp
@@ -44,8 +44,7 @@
   ASSERT_NE(id, -1);
 
   // Check segment info.
-  shmid_ds ds;
-  memset(&ds, 0, sizeof(ds));
+  shmid_ds ds = {};
   ASSERT_EQ(0, shmctl(id, IPC_STAT, &ds));
   ASSERT_EQ(1234U, ds.shm_segsz);
 
diff --git a/tests/sys_socket_test.cpp b/tests/sys_socket_test.cpp
index 1cfbfb2..559ee7d 100644
--- a/tests/sys_socket_test.cpp
+++ b/tests/sys_socket_test.cpp
@@ -42,10 +42,7 @@
     return reinterpret_cast<void*>(-1);
   }
 
-  struct sockaddr_un addr;
-  memset(&addr, 0, sizeof(addr));
-  addr.sun_family = AF_UNIX;
-  addr.sun_path[0] = '\0';
+  struct sockaddr_un addr = {.sun_family = AF_UNIX, .sun_path[0] = '\0'};
   strcpy(addr.sun_path + 1, pdata->sock_path);
 
   if (connect(fd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)) < 0) {
@@ -66,10 +63,7 @@
   int fd = socket(PF_UNIX, SOCK_SEQPACKET, 0);
   ASSERT_NE(fd, -1) << strerror(errno);
 
-  struct sockaddr_un addr;
-  memset(&addr, 0, sizeof(addr));
-  addr.sun_family = AF_UNIX;
-  addr.sun_path[0] = '\0';
+  struct sockaddr_un addr = {.sun_family = AF_UNIX, .sun_path[0] = '\0'};
   strcpy(addr.sun_path + 1, sock_path);
 
   ASSERT_NE(-1, bind(fd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr))) << strerror(errno);
@@ -141,9 +135,7 @@
   int fd_acc = accept(fd, reinterpret_cast<struct sockaddr*>(addr), &len);
   ASSERT_NE(fd_acc, -1) << strerror(errno);
 
-  struct mmsghdr msgs[NUM_RECV_MSGS];
-  memset(msgs, 0, sizeof(struct mmsghdr)*NUM_RECV_MSGS);
-
+  struct mmsghdr msgs[NUM_RECV_MSGS] = {};
   struct iovec io[NUM_RECV_MSGS];
   char bufs[NUM_RECV_MSGS][100];
   for (size_t i = 0; i < NUM_RECV_MSGS; i++) {
@@ -155,10 +147,7 @@
     msgs[i].msg_len = sizeof(struct msghdr);
   }
 
-  struct timespec ts;
-  memset(&ts, 0, sizeof(ts));
-  ts.tv_sec = 5;
-  ts.tv_nsec = 0;
+  struct timespec ts = {.tv_sec = 5, .tv_nsec = 0};
   ASSERT_EQ(NUM_RECV_MSGS,
             static_cast<size_t>(recvmmsg(fd_acc, msgs, NUM_RECV_MSGS, 0, &ts)))
            << strerror(errno);
@@ -189,8 +178,7 @@
 #define NUM_SEND_MSGS (sizeof(g_SendMsgs)/sizeof(const char*))
 
 static bool SendMMsg(int fd) {
-  struct mmsghdr msgs[NUM_SEND_MSGS];
-  memset(msgs, 0, sizeof(struct mmsghdr)*NUM_SEND_MSGS);
+  struct mmsghdr msgs[NUM_SEND_MSGS] = {};
   struct iovec io[NUM_SEND_MSGS];
   for (size_t i = 0; i < NUM_SEND_MSGS; i++) {
     io[i].iov_base = reinterpret_cast<void*>(const_cast<char*>(g_SendMsgs[i]));
diff --git a/tests/sys_sysinfo_test.cpp b/tests/sys_sysinfo_test.cpp
index 69656ad..b8bcf92 100644
--- a/tests/sys_sysinfo_test.cpp
+++ b/tests/sys_sysinfo_test.cpp
@@ -39,8 +39,7 @@
 }
 
 TEST(sys_sysinfo, sysinfo) {
-  struct sysinfo si;
-  memset(&si, 0, sizeof(si));
+  struct sysinfo si = {};
   ASSERT_EQ(0, sysinfo(&si));
 
   ASSERT_GT(static_cast<long>(si.uptime), 10);  // You're not running CTS within 10s of booting!
diff --git a/tests/sys_timex_test.cpp b/tests/sys_timex_test.cpp
index 44b73c9..627c1ee 100644
--- a/tests/sys_timex_test.cpp
+++ b/tests/sys_timex_test.cpp
@@ -21,15 +21,13 @@
 #include <gtest/gtest.h>
 
 TEST(sys_timex, adjtimex_smoke) {
-  timex t;
-  memset(&t, 0, sizeof(t));
+  timex t = {};
   // adjtimex/clock_adjtime return the clock state on success, -1 on failure.
   ASSERT_NE(-1, adjtimex(&t));
 }
 
 TEST(sys_timex, clock_adjtime_smoke) {
-  timex t;
-  memset(&t, 0, sizeof(t));
+  timex t = {};
   // adjtimex/clock_adjtime return the clock state on success, -1 on failure.
   ASSERT_NE(-1, clock_adjtime(CLOCK_REALTIME, &t));
 }
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index baafbf6..cf4de06 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -126,8 +126,7 @@
   // tzcode used to have a bug where it didn't reinitialize some internal state.
 
   // Choose a time where DST is set.
-  struct tm t;
-  memset(&t, 0, sizeof(tm));
+  struct tm t = {};
   t.tm_year = 1980 - 1900;
   t.tm_mon = 6;
   t.tm_mday = 2;
@@ -136,7 +135,7 @@
   tzset();
   ASSERT_EQ(static_cast<time_t>(331372800U), mktime(&t));
 
-  memset(&t, 0, sizeof(tm));
+  t = {};
   t.tm_year = 1980 - 1900;
   t.tm_mon = 6;
   t.tm_mday = 2;
@@ -173,8 +172,7 @@
 TEST(time, mktime_EOVERFLOW) {
   setenv("TZ", "UTC", 1);
 
-  struct tm t;
-  memset(&t, 0, sizeof(tm));
+  struct tm t = {};
 
   // LP32 year range is 1901-2038, so this year is guaranteed not to overflow.
   t.tm_year = 2016 - 1900;
@@ -212,8 +210,7 @@
 TEST(time, mktime_invalid_tm_TZ_combination) {
   setenv("TZ", "UTC", 1);
 
-  struct tm t;
-  memset(&t, 0, sizeof(tm));
+  struct tm t = {};
   t.tm_year = 2022 - 1900;
   t.tm_mon = 11;
   t.tm_mday = 31;
@@ -248,8 +245,7 @@
 TEST(time, strftime) {
   setenv("TZ", "UTC", 1);
 
-  struct tm t;
-  memset(&t, 0, sizeof(tm));
+  struct tm t = {};
   t.tm_year = 200;
   t.tm_mon = 2;
   t.tm_mday = 10;
@@ -270,8 +266,7 @@
 TEST(time, strftime_second_before_epoch) {
   setenv("TZ", "UTC", 1);
 
-  struct tm t;
-  memset(&t, 0, sizeof(tm));
+  struct tm t = {};
   t.tm_year = 1969 - 1900;
   t.tm_mon = 11;
   t.tm_mday = 31;
@@ -287,9 +282,7 @@
 
 TEST(time, strftime_Z_null_tm_zone) {
   // Netflix on Nexus Player wouldn't start (http://b/25170306).
-  struct tm t;
-  memset(&t, 0, sizeof(tm));
-
+  struct tm t = {};
   char buf[64];
 
   setenv("TZ", "America/Los_Angeles", 1);
@@ -409,8 +402,7 @@
 
   setenv("TZ", "UTC", 1);
 
-  struct tm t;
-  memset(&t, 0, sizeof(tm));
+  struct tm t = {};
   t.tm_year = 200;
   t.tm_mon = 2;
   t.tm_mday = 10;
@@ -427,15 +419,14 @@
 TEST(time, strptime) {
   setenv("TZ", "UTC", 1);
 
-  struct tm t;
+  struct tm t = {};
   char buf[64];
 
-  memset(&t, 0, sizeof(t));
   strptime("11:14", "%R", &t);
   strftime(buf, sizeof(buf), "%H:%M", &t);
   EXPECT_STREQ("11:14", buf);
 
-  memset(&t, 0, sizeof(t));
+  t = {};
   strptime("09:41:53", "%T", &t);
   strftime(buf, sizeof(buf), "%H:%M:%S", &t);
   EXPECT_STREQ("09:41:53", buf);
@@ -445,15 +436,14 @@
 #if !defined(ANDROID_HOST_MUSL)
   setenv("TZ", "UTC", 1);
 
-  struct tm t;
+  struct tm t = {};
   char buf[64];
 
-  memset(&t, 0, sizeof(t));
   strptime_l("11:14", "%R", &t, LC_GLOBAL_LOCALE);
   strftime_l(buf, sizeof(buf), "%H:%M", &t, LC_GLOBAL_LOCALE);
   EXPECT_STREQ("11:14", buf);
 
-  memset(&t, 0, sizeof(t));
+  t = {};
   strptime_l("09:41:53", "%T", &t, LC_GLOBAL_LOCALE);
   strftime_l(buf, sizeof(buf), "%H:%M:%S", &t, LC_GLOBAL_LOCALE);
   EXPECT_STREQ("09:41:53", buf);
@@ -637,8 +627,7 @@
 }
 
 TEST(time, timer_create) {
-  sigevent se;
-  memset(&se, 0, sizeof(se));
+  sigevent se = {};
   se.sigev_notify = SIGEV_THREAD;
   se.sigev_notify_function = NoOpNotifyFunction;
   timer_t timer_id;
@@ -666,8 +655,7 @@
 }
 
 TEST(time, timer_create_SIGEV_SIGNAL) {
-  sigevent se;
-  memset(&se, 0, sizeof(se));
+  sigevent se = {};
   se.sigev_notify = SIGEV_SIGNAL;
   se.sigev_signo = SIGUSR1;
 
@@ -705,10 +693,7 @@
 
  public:
   explicit Counter(void (*fn)(sigval)) : value(0), timer_valid(false) {
-    memset(&se, 0, sizeof(se));
-    se.sigev_notify = SIGEV_THREAD;
-    se.sigev_notify_function = fn;
-    se.sigev_value.sival_ptr = this;
+    se = {.sigev_notify = SIGEV_THREAD, .sigev_notify_function = fn, .sigev_value.sival_ptr = this};
     Create();
   }
   void DeleteTimer() {
@@ -909,9 +894,7 @@
 
 TEST(time, timer_delete_from_timer_thread) {
   TimerDeleteData tdd;
-  sigevent se;
-
-  memset(&se, 0, sizeof(se));
+  sigevent se = {};
   se.sigev_notify = SIGEV_THREAD;
   se.sigev_notify_function = TimerDeleteCallback;
   se.sigev_value.sival_ptr = &tdd;
@@ -1252,11 +1235,9 @@
   strftime(buf, sizeof(buf), "<%s>", &tm0);
   EXPECT_STREQ("<378691200>", buf);
 
-  struct tm tm;
-
   setenv("TZ", "America/Los_Angeles", 1);
   tzset();
-  memset(&tm, 0xff, sizeof(tm));
+  struct tm tm = {};
   char* p = strptime("378720000x", "%s", &tm);
   ASSERT_EQ('x', *p);
   EXPECT_EQ(0, tm.tm_sec);
@@ -1271,7 +1252,7 @@
 
   setenv("TZ", "UTC", 1);
   tzset();
-  memset(&tm, 0xff, sizeof(tm));
+  tm = {};
   p = strptime("378691200x", "%s", &tm);
   ASSERT_EQ('x', *p);
   EXPECT_EQ(0, tm.tm_sec);
diff --git a/tests/uchar_test.cpp b/tests/uchar_test.cpp
index fd3b332..b554ee5 100644
--- a/tests/uchar_test.cpp
+++ b/tests/uchar_test.cpp
@@ -73,9 +73,8 @@
   uselocale(LC_GLOBAL_LOCALE);
 
   char out[MB_LEN_MAX];
-  mbstate_t ps;
+  mbstate_t ps = {};
 
-  memset(&ps, 0, sizeof(ps));
   EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(nullptr, "\xc2", 1, &ps));
   errno = 0;
   EXPECT_EQ(static_cast<size_t>(-1), c32rtomb(out, 0x00a2, &ps));
@@ -86,12 +85,12 @@
 
   // If the first argument to c32rtomb is nullptr or the second is L'\0' the shift
   // state should be reset.
-  memset(&ps, 0, sizeof(ps));
+  ps = {};
   EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(nullptr, "\xc2", 1, &ps));
   EXPECT_EQ(1U, c32rtomb(nullptr, 0x00a2, &ps));
   EXPECT_TRUE(mbsinit(&ps));
 
-  memset(&ps, 0, sizeof(ps));
+  ps = {};
   EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(nullptr, "\xf0\xa4", 1, &ps));
   EXPECT_EQ(1U, c32rtomb(out, L'\0', &ps));
   EXPECT_TRUE(mbsinit(&ps));
@@ -299,8 +298,7 @@
   ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
   uselocale(LC_GLOBAL_LOCALE);
 
-  mbstate_t ps;
-  memset(&ps, 0, sizeof(ps));
+  mbstate_t ps = {};
 
   test_mbrtoc16_incomplete(&ps);
   test_mbrtoc16_incomplete(nullptr);
@@ -475,8 +473,7 @@
   ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
   uselocale(LC_GLOBAL_LOCALE);
 
-  mbstate_t ps;
-  memset(&ps, 0, sizeof(ps));
+  mbstate_t ps = {};
 
   test_mbrtoc32_incomplete(&ps);
   test_mbrtoc32_incomplete(nullptr);
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 9ad3b6d..3143c23 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -1393,9 +1393,7 @@
 }
 
 TEST(UNISTD_TEST, setdomainname) {
-  __user_cap_header_struct header;
-  memset(&header, 0, sizeof(header));
-  header.version = _LINUX_CAPABILITY_VERSION_3;
+  __user_cap_header_struct header = {.version = _LINUX_CAPABILITY_VERSION_3};
 
   __user_cap_data_struct old_caps[_LINUX_CAPABILITY_U32S_3];
   ASSERT_EQ(0, capget(&header, &old_caps[0]));
diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp
index a811fd8..ba2a4d8 100644
--- a/tests/wchar_test.cpp
+++ b/tests/wchar_test.cpp
@@ -130,22 +130,21 @@
   uselocale(LC_GLOBAL_LOCALE);
 
   char out[MB_LEN_MAX];
-  mbstate_t ps;
+  mbstate_t ps = {};
 
   // Any non-initial state is invalid when calling wcrtomb.
-  memset(&ps, 0, sizeof(ps));
   EXPECT_EQ(static_cast<size_t>(-2), mbrtowc(nullptr, "\xc2", 1, &ps));
   EXPECT_EQ(static_cast<size_t>(-1), wcrtomb(out, 0x00a2, &ps));
   EXPECT_ERRNO(EILSEQ);
 
   // If the first argument to wcrtomb is NULL or the second is L'\0' the shift
   // state should be reset.
-  memset(&ps, 0, sizeof(ps));
+  ps = {};
   EXPECT_EQ(static_cast<size_t>(-2), mbrtowc(nullptr, "\xc2", 1, &ps));
   EXPECT_EQ(1U, wcrtomb(nullptr, 0x00a2, &ps));
   EXPECT_TRUE(mbsinit(&ps));
 
-  memset(&ps, 0, sizeof(ps));
+  ps = {};
   EXPECT_EQ(static_cast<size_t>(-2), mbrtowc(nullptr, "\xf0\xa4", 1, &ps));
   EXPECT_EQ(1U, wcrtomb(out, L'\0', &ps));
   EXPECT_TRUE(mbsinit(&ps));
@@ -253,9 +252,8 @@
   EXPECT_STREQ("hix", bytes);
 
   // Any non-initial state is invalid when calling wcsrtombs.
-  mbstate_t ps;
+  mbstate_t ps = {};
   src = chars;
-  memset(&ps, 0, sizeof(ps));
   ASSERT_EQ(static_cast<size_t>(-2), mbrtowc(nullptr, "\xc2", 1, &ps));
   EXPECT_EQ(static_cast<size_t>(-1), wcsrtombs(nullptr, &src, 0, &ps));
   EXPECT_ERRNO(EILSEQ);
@@ -449,8 +447,7 @@
 }
 
 TEST(wchar, mbrtowc_incomplete) {
-  mbstate_t ps;
-  memset(&ps, 0, sizeof(ps));
+  mbstate_t ps = {};
 
   test_mbrtowc_incomplete(&ps);
   test_mbrtowc_incomplete(nullptr);
@@ -508,8 +505,7 @@
   ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8"));
   uselocale(LC_GLOBAL_LOCALE);
 
-  mbstate_t ps;
-  memset(&ps, 0, sizeof(ps));
+  mbstate_t ps = {};
   test_mbsrtowcs(&ps);
   test_mbsrtowcs(nullptr);
 
@@ -659,12 +655,7 @@
 TEST(wchar, wcsftime__wcsftime_l) {
   setenv("TZ", "UTC", 1);
 
-  struct tm t;
-  memset(&t, 0, sizeof(tm));
-  t.tm_year = 200;
-  t.tm_mon = 2;
-  t.tm_mday = 10;
-
+  struct tm t = {.tm_year = 200, .tm_mon = 2, .tm_mday = 10};
   wchar_t buf[64];
 
   EXPECT_EQ(24U, wcsftime(buf, sizeof(buf), L"%c", &t));