Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
xstring usage: prefer fputs over fprintf where possible
Baptiste Daroussin committed 5 years ago
commit 720878c0618aca0227125fb2bdb7fb400d17511c
parent fda1378
7 files changed +41 -40
modified libpkg/fetch_libfetch.c
@@ -97,7 +97,7 @@ fetch_connect(struct pkg_repo *repo, struct url *u)
	int retcode = EPKG_OK;
	char docpath[MAXPATHLEN];
	char zone[MAXHOSTNAMELEN + 24];
-
	char *doc, *reldoc;
+
	char *doc, *reldoc, *opts;
	struct dns_srvinfo *srv_current = NULL;
	struct http_mirror *http_current = NULL;
	struct url_stat st;
@@ -160,19 +160,20 @@ fetch_connect(struct pkg_repo *repo, struct url *u)
			u->port = http_current->url->port;
		}
		fetchOpts = xstring_new();
-
		fprintf(fetchOpts->fp, "i");
+
		fputs("i", fetchOpts->fp);
		if (repo != NULL) {
			if ((repo->flags & REPO_FLAGS_USE_IPV4) ==
			    REPO_FLAGS_USE_IPV4)
-
				fprintf(fetchOpts->fp, "4");
+
				fputs("4", fetchOpts->fp);
			else if ((repo->flags & REPO_FLAGS_USE_IPV6) ==
			    REPO_FLAGS_USE_IPV6)
-
				fprintf(fetchOpts->fp, "6");
+
				fputs("6", fetchOpts->fp);
		}

		if (ctx.debug_level >= 4)
-
			fprintf(fetchOpts->fp, "v");
+
			fputs("v", fetchOpts->fp);

+
		opts = xstring_get(fetchOpts);
		fflush(fetchOpts->fp);
		pkg_debug(1,"Fetch: fetching from: %s://%s%s%s%s with opts \"%s\"",
		    u->scheme,
@@ -180,11 +181,10 @@ fetch_connect(struct pkg_repo *repo, struct url *u)
		    u->user[0] != '\0' ? "@" : "",
		    u->host,
		    u->doc,
-
		    fetchOpts->buf);
+
		    opts);

-
		repo->fh = fetchXGet(u, &st, fetchOpts->buf);
+
		repo->fh = fetchXGet(u, &st, opts);
		u->ims_time = st.mtime;
-
		xstring_free(fetchOpts);
		if (repo->fh == NULL) {
			if (fetchLastErrCode == FETCH_OK) {
				retcode = EPKG_UPTODATE;
modified libpkg/fetch_ssh.c
@@ -57,6 +57,7 @@ ssh_connect(struct pkg_repo *repo, struct url *u)
	int sshin[2];
	int sshout[2];
	xstring *cmd = NULL;
+
	char *cmdline;
	int retcode = EPKG_FATAL;
	const char *ssh_args;
	const char *argv[4];
@@ -83,26 +84,25 @@ ssh_connect(struct pkg_repo *repo, struct url *u)
		}

		cmd = xstring_new();
-
		fprintf(cmd->fp, "/usr/bin/ssh -e none -T ");
+
		fputs("/usr/bin/ssh -e none -T ", cmd->fp);

		ssh_args = pkg_object_string(pkg_config_get("PKG_SSH_ARGS"));
		if (ssh_args != NULL)
			fprintf(cmd->fp, "%s ", ssh_args);
		if ((repo->flags & REPO_FLAGS_USE_IPV4) == REPO_FLAGS_USE_IPV4)
-
			fprintf(cmd->fp, "-4 ");
+
			fputs("-4 ", cmd->fp);
		else if ((repo->flags & REPO_FLAGS_USE_IPV6) == REPO_FLAGS_USE_IPV6)
-
			fprintf(cmd->fp, "-6 ");
+
			fputs("-6 ", cmd->fp);
		if (u->port > 0)
			fprintf(cmd->fp, "-p %d ", u->port);
		if (u->user[0] != '\0')
			fprintf(cmd->fp, "%s@", u->user);
-
		fprintf(cmd->fp, "%s", u->host);
-
		fprintf(cmd->fp, " pkg ssh");
-
		fflush(cmd->fp);
-
		pkg_debug(1, "Fetch: running '%s'", cmd->buf);
+
		fprintf(cmd->fp, "%s pkg ssh", u->host);
+
		cmdline = xstring_get(cmd);
+
		pkg_debug(1, "Fetch: running '%s'", cmdline);
		argv[0] = _PATH_BSHELL;
		argv[1] = "-c";
-
		argv[2] = cmd->buf;
+
		argv[2] = cmdline;
		argv[3] = NULL;

		if (sshin[0] != STDIN_FILENO)
modified libpkg/lua_scripts.c
@@ -60,11 +60,12 @@ stack_dump(lua_State *L)
	int i;
	int top = lua_gettop(L);
	xstring *stack;
+
	char *stackstr;

	stack = xstring_new();

-
	fprintf(stack->fp, "\nLua Stack\n---------\n");
-
	fprintf(stack->fp, "\tType   Data\n\t-----------\n" );
+
	fputs("\nLua Stack\n---------\n"
+
	    "\tType   Data\n\t-----------\n", stack->fp);

	for (i = 1; i <= top; i++) {  /* repeat for each level */
		int t = lua_type(L, i);
@@ -84,9 +85,9 @@ stack_dump(lua_State *L)
			break;
		}
	}
-
	fflush(stack->fp);
-
	pkg_emit_error("%s\n", stack->buf);
-
	xstring_free(stack);
+
	stackstr = xstring_get(stack);
+
	pkg_emit_error("%s\n", stackstr);
+
	free(stackstr);

	return (0);
}
modified libpkg/packing.c
@@ -270,7 +270,7 @@ packing_append_tree(struct packing *pack, const char *treepath,
	FTS *fts = NULL;
	FTSENT *fts_e = NULL;
	size_t treelen;
-
	xstring *sb;
+
	xstring *sb = NULL;
	char *paths[2] = { __DECONST(char *, treepath), NULL };

	treelen = strlen(treepath);
@@ -278,8 +278,8 @@ packing_append_tree(struct packing *pack, const char *treepath,
	if (fts == NULL)
		goto cleanup;

-
	sb = xstring_new();
	while ((fts_e = fts_read(fts)) != NULL) {
+
		xstring_renew(sb);
		switch(fts_e->fts_info) {
		case FTS_D:
		case FTS_DEFAULT:
@@ -292,9 +292,9 @@ packing_append_tree(struct packing *pack, const char *treepath,
			 xstring_reset(sb);
			 /* Strip the prefix to obtain the target path */
			 if (newroot) /* Prepend a root if one is specified */
-
				  fprintf(sb->fp, "%s", newroot);
+
				  fputs(newroot, sb->fp);
			 /* +1 = skip trailing slash */
-
			 fprintf(sb->fp, "%s", fts_e->fts_path + treelen + 1);
+
			 fputs(fts_e->fts_path + treelen + 1, sb->fp);
			 fflush(sb->fp);
			 packing_append_file_attr(pack, fts_e->fts_name,
			    sb->buf, NULL, NULL, 0, 0);
modified libpkg/pkg_audit.c
@@ -535,7 +535,7 @@ static void
vulnxml_val_attribute(struct vulnxml_userdata *ud, yxml_t *xml)
{
	if (ud->state == VULNXML_PARSE_VULN && ud->attr == VULNXML_ATTR_VID) {
-
		fprintf(ud->content->fp, "%s", xml->data);
+
		fputs(xml->data, ud->content->fp);
	}
}

@@ -558,7 +558,7 @@ vulnxml_handle_data(struct vulnxml_userdata *ud, yxml_t *xml)
	case VULNXML_PARSE_RANGE_LT:
	case VULNXML_PARSE_RANGE_LE:
	case VULNXML_PARSE_RANGE_EQ:
-
		fprintf(ud->content->fp, "%s", xml->data);
+
		fputs(xml->data, ud->content->fp);
		break;
	}
}
modified libpkg/pkg_event.c
@@ -45,8 +45,8 @@ buf_json_escape(const char *str)

	while (str != NULL && *str != '\0') {
		if (*str == '"' || *str == '\\')
-
			fprintf(buf->fp, "%c", '\\');
-
		fprintf(buf->fp, "%c", *str);
+
			fputc('\\', buf->fp);
+
		fputc(*str, buf->fp);
		str++;
	}

@@ -162,8 +162,8 @@ pipeevent(struct pkg_event *ev)
				"");
		break;
	case PKG_EVENT_INTEGRITYCHECK_BEGIN:
-
		fprintf(msg->fp, "{ \"type\": \"INFO_INTEGRITYCHECK_BEGIN\", "
-
		    "\"data\": {}}");
+
		fputs("{ \"type\": \"INFO_INTEGRITYCHECK_BEGIN\", "
+
		    "\"data\": {}}", msg->fp);
		break;
	case PKG_EVENT_INTEGRITYCHECK_CONFLICT:
		fprintf(msg->fp, "{ \"type\": \"INFO_INTEGRITYCHECK_CONFLICT\","
@@ -186,7 +186,7 @@ pipeevent(struct pkg_event *ev)
			}
			cur_conflict = cur_conflict->next;
		}
-
		fprintf(msg->fp, "%s", "]}}");
+
		fputs("]}}", msg->fp);
		break;
	case PKG_EVENT_INTEGRITYCHECK_FINISHED:
		fprintf(msg->fp, "{ \"type\": \"INFO_INTEGRITYCHECK_FINISHED\", "
@@ -259,7 +259,7 @@ pipeevent(struct pkg_event *ev)
		int c = 0;
		ungetc(c, msg->fp);
		ungetc(c, msg->fp);
-
		fprintf(msg->fp, "%s", "]}}");
+
		fputs("]}}", msg->fp);
		break;
	case PKG_EVENT_ALREADY_INSTALLED:
		pkg_fprintf(msg->fp, "{ \"type\": \"ERROR_ALREADY_INSTALLED\", "
@@ -287,12 +287,12 @@ pipeevent(struct pkg_event *ev)
		    ev->e_remotedb.repo);
		break;
	case PKG_EVENT_NOLOCALDB:
-
		fprintf(msg->fp, "{ \"type\": \"ERROR_NOLOCALDB\", "
-
		    "\"data\": {}} ");
+
		fputs("{ \"type\": \"ERROR_NOLOCALDB\", \"data\": {}} ",
+
		    msg->fp);
		break;
	case PKG_EVENT_NEWPKGVERSION:
-
		fprintf(msg->fp, "{ \"type\": \"INFO_NEWPKGVERSION\", "
-
		    "\"data\": {}} ");
+
		fputs("{ \"type\": \"INFO_NEWPKGVERSION\", \"data\": {}} ",
+
		    msg->fp);
		break;
	case PKG_EVENT_FILE_MISMATCH:
		pkg_fprintf(msg->fp, "{ \"type\": \"ERROR_FILE_MISMATCH\", "
@@ -371,8 +371,8 @@ pipeevent(struct pkg_event *ev)
			ev->e_query_select.items[i]);
		break;
	case PKG_EVENT_PROGRESS_START:
-
		fprintf(msg->fp, "{ \"type\": \"INFO_PROGRESS_START\", "
-
		  "\"data\": {}}");
+
		fputs("{ \"type\": \"INFO_PROGRESS_START\", \"data\": {}}",
+
		    msg->fp);
		break;
	case PKG_EVENT_PROGRESS_TICK:
		fprintf(msg->fp, "{ \"type\": \"INFO_PROGRESS_TICK\", "
modified libpkg/plugins.c
@@ -151,7 +151,7 @@ pkg_plugin_set(struct pkg_plugin *p, pkg_plugin_key key, const char *str)
	assert(p != NULL);

	xstring_renew(p->fields[key]);
-
	fprintf(p->fields[key]->fp, "%s", str);
+
	fputs(str, p->fields[key]->fp);
	fflush(p->fields[key]->fp);
	return (EPKG_OK);
}