From 9883015be2b2010ad541fd02b6856bfdb28fb35d Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 24 Dec 2019 10:28:11 -0500 Subject: Use c99 struct initialization to avoid memset calls This is guaranteed less error prone than calling memset and hoping the human gets the argument order correct. --- lib/libalpm/dload.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'lib/libalpm/dload.c') diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 40a1d07d..b3e6a411 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -195,9 +195,10 @@ static int curl_gethost(const char *url, char *buffer, size_t buf_len) static int utimes_long(const char *path, long seconds) { if(seconds != -1) { - struct timeval tv[2]; - memset(&tv, 0, sizeof(tv)); - tv[0].tv_sec = tv[1].tv_sec = seconds; + struct timeval tv[2] = { + { .tv_sec = seconds, }, + { .tv_sec = seconds, }, + }; return utimes(path, tv); } return 0; @@ -657,7 +658,7 @@ char SYMEXPORT *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url) char *filepath; const char *cachedir, *final_pkg_url = NULL; char *final_file = NULL; - struct dload_payload payload; + struct dload_payload payload = {0}; int ret = 0; CHECK_HANDLE(handle, return NULL); @@ -666,8 +667,6 @@ char SYMEXPORT *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url) /* find a valid cache dir to download to */ cachedir = _alpm_filecache_setup(handle); - memset(&payload, 0, sizeof(struct dload_payload)); - /* attempt to find the file in our pkgcache */ filepath = filecache_find_url(handle, url); if(filepath == NULL) { @@ -740,7 +739,7 @@ void _alpm_dload_payload_reset(struct dload_payload *payload) FREE(payload->destfile_name); FREE(payload->content_disp_name); FREE(payload->fileurl); - memset(payload, '\0', sizeof(*payload)); + *payload = (struct dload_payload){0}; } void _alpm_dload_payload_reset_for_retry(struct dload_payload *payload) -- cgit v1.2.3-24-g4f1b