Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
cleanup: replace memset with some inline declaration
Baptiste Daroussin committed 3 years ago
commit 8cfcfbc694c614cbd1c6fc9e1c5e7dee6d55d7ab
parent e0d681c
8 files changed +14 -28
modified libpkg/dns_utils.c
@@ -276,16 +276,14 @@ set_nameserver(const char *nsname) {
#ifndef HAVE___RES_SETSERVERS
	return (-1);
#else
-
	struct __res_state res;
+
	struct __res_state res = { 0 };
	union res_sockaddr_union u[MAXNS];
	struct addrinfo *answer = NULL;
	struct addrinfo *cur = NULL;
-
	struct addrinfo hint;
+
	struct addrinfo hint = { 0 };
	int nscount = 0;

	memset(u, 0, sizeof(u));
-
	memset(&hint, 0, sizeof(hint));
-
	memset(&res, 0, sizeof(res));
	hint.ai_socktype = SOCK_DGRAM;
	hint.ai_flags = AI_NUMERICHOST;

modified libpkg/fetch_ssh.c
@@ -57,13 +57,12 @@ tcp_connect(struct pkg_repo *repo, struct url *u)
{
	char *line = NULL;
	size_t linecap = 0;
-
	struct addrinfo *ai = NULL, *curai, hints;
+
	struct addrinfo *ai = NULL, *curai, hints = { 0 };
	char srv[NI_MAXSERV];
	int sd = -1;
	int retcode;

	pkg_debug(1, "TCP> tcp_connect");
-
	memset(&hints, 0, sizeof(hints));
	hints.ai_family = PF_UNSPEC;
	if ((repo->flags & REPO_FLAGS_USE_IPV4) == REPO_FLAGS_USE_IPV4)
		hints.ai_family = PF_INET;
@@ -328,13 +327,11 @@ static int
ssh_writev(int fd, struct iovec *iov, int iovcnt)
{
	struct timeval now, timeout, delta;
-
	struct pollfd pfd;
+
	struct pollfd pfd = { 0 };
	ssize_t wlen, total;
	int deltams;
	struct msghdr msg;

-
	memset(&pfd, 0, sizeof pfd);
-

	if (fetchTimeout) {
		pfd.fd = fd;
		pfd.events = POLLOUT | POLLERR;
modified libpkg/pkg_config.c
@@ -512,7 +512,7 @@ static void pkg_repo_free(struct pkg_repo *r);
static void
connect_evpipe(const char *evpipe) {
	struct stat st;
-
	struct sockaddr_un sock;
+
	struct sockaddr_un sock = { 0 };
	int flag = O_WRONLY;

	if (stat(evpipe, &st) != 0) {
@@ -537,7 +537,6 @@ connect_evpipe(const char *evpipe) {
			pkg_emit_errno("Open event pipe", evpipe);
			return;
		}
-
		memset(&sock, 0, sizeof(struct sockaddr_un));
		sock.sun_family = AF_UNIX;
		if (strlcpy(sock.sun_path, evpipe, sizeof(sock.sun_path)) >=
		    sizeof(sock.sun_path)) {
@@ -1001,7 +1000,7 @@ pkg_ini(const char *path, const char *reposdir, pkg_init_flags flags)
	bool fatal_errors = false;
	int conffd = -1;
	char *tmp = NULL;
-
	struct os_info oi;
+
	struct os_info oi = { 0 };
	size_t ukeylen;
	int err = EPKG_OK;

@@ -1013,7 +1012,6 @@ pkg_ini(const char *path, const char *reposdir, pkg_init_flags flags)
		return (EPKG_FATAL);
	}

-
	memset(&oi, 0, sizeof(oi));
	pkg_get_myarch(myabi, BUFSIZ, &oi);
	pkg_get_myarch_legacy(myabi_legacy, BUFSIZ);
#ifdef __FreeBSD__
modified libpkg/pkg_cudf.c
@@ -442,9 +442,7 @@ pkg_jobs_cudf_parse_output(struct pkg_jobs *j, FILE *f)
{
	char *line = NULL, *begin, *param, *value;
	size_t linecap = 0;
-
	struct pkg_cudf_entry cur_pkg;
-

-
	memset(&cur_pkg, 0, sizeof(cur_pkg));
+
	struct pkg_cudf_entry cur_pkg = { 0 };

	while (getline(&line, &linecap, f) > 0) {
		/* Split line, cut spaces */
modified libpkg/pkg_elf.c
@@ -827,7 +827,7 @@ pkg_get_myarch_elfparse(char *dest, size_t sz, struct os_info *oi)
	int ret = EPKG_OK;
	const char *arch, *abi, *endian_corres_str, *wordsize_corres_str, *fpu;
	bool checkroot;
-
	struct os_info loi;
+
	struct os_info loi = { 0 };

	const char *abi_files[] = {
		getenv("ABI_FILE"),
@@ -837,10 +837,8 @@ pkg_get_myarch_elfparse(char *dest, size_t sz, struct os_info *oi)

	arch = NULL;

-
	if (oi == NULL) {
-
		memset(&loi, 0, sizeof(loi));
+
	if (oi == NULL)
		oi = &loi;
-
	}

	if (elf_version(EV_CURRENT) == EV_NONE) {
		pkg_emit_error("ELF library initialization failed: %s",
modified libpkg/pkg_repo_create.c
@@ -325,11 +325,10 @@ static void
tell_parent(int fd, char *buf, size_t len)
{
	struct iovec iov[2];
-
	struct msghdr msg;
+
	struct msghdr msg = { 0 };

	iov[0].iov_base = buf;
	iov[0].iov_len = len;
-
	memset(&msg, 0, sizeof(msg));
	msg.msg_iov = iov;
	msg.msg_iovlen = 1;
	sendmsg(fd, &msg, MSG_EOR);
modified libpkg/scripts.c
@@ -265,13 +265,12 @@ cleanup:


int
-
pkg_script_run_child(int pid, int *pstat, int inputfd, const char* script_name) {
-
	struct pollfd pfd;
+
pkg_script_run_child(int pid, int *pstat, int inputfd, const char* script_name)
+
{
+
	struct pollfd pfd = { 0 };
	bool wait_for_child;
	char msgbuf[16384+1];

-

-
	memset(&pfd, 0, sizeof(pfd));
	pfd.events = POLLIN | POLLERR | POLLHUP;
	pfd.fd = inputfd;

modified src/utils.c
@@ -937,12 +937,11 @@ print_jobs_summary(struct pkg_jobs *jobs, const char *msg, ...)
	struct pkg_solved_display **displays;
	bool first = true;
	size_t bytes_change, limbytes;
-
	struct jobs_sum_number sum;
+
	struct jobs_sum_number sum = { 0 };

	dlsize = oldsize = newsize = 0;
	type = pkg_jobs_type(jobs);
	memset(disp, 0, sizeof(*disp) * PKG_DISPLAY_MAX);
-
	memset(&sum, 0, sizeof(sum));

	nbtodl = 0;
	while (pkg_jobs_iter(jobs, &iter, &new_pkg, &old_pkg, &type)) {