use plain write() in place of dprintf() with a pre-formatted string step-by-step guidance from millert; ok millert stsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
diff --git a/got/got.c b/got/got.c
index 3a7013a..0ddfc1d 100644
--- a/got/got.c
+++ b/got/got.c
@@ -487,11 +487,13 @@ collect_import_msg(char **logmsg, char **logmsg_path, const char *editor,
{
char *initial_content = NULL;
const struct got_error *err = NULL;
+ int initial_content_len;
int fd;
- if (asprintf(&initial_content,
+ initial_content_len = asprintf(&initial_content,
"\n# %s to be imported to branch %s\n", path_dir,
- branch_name) == -1)
+ branch_name);
+ if (initial_content_len == -1)
return got_error_from_errno("asprintf");
err = got_opentemp_named_fd(logmsg_path, &fd,
@@ -499,7 +501,7 @@ collect_import_msg(char **logmsg, char **logmsg_path, const char *editor,
if (err)
goto done;
- dprintf(fd, initial_content);
+ write(fd, initial_content, initial_content_len);
close(fd);
err = edit_logmsg(logmsg, editor, *logmsg_path, initial_content);
@@ -5643,6 +5645,7 @@ get_tag_message(char **tagmsg, char **tagmsg_path, const char *commit_id_str,
const struct got_error *err = NULL;
char *template = NULL, *initial_content = NULL;
char *editor = NULL;
+ int initial_content_len;
int fd = -1;
if (asprintf(&template, GOT_TMPDIR_STR "/got-tagmsg") == -1) {
@@ -5650,8 +5653,10 @@ get_tag_message(char **tagmsg, char **tagmsg_path, const char *commit_id_str,
goto done;
}
- if (asprintf(&initial_content, "\n# tagging commit %s as %s\n",
- commit_id_str, tag_name) == -1) {
+ initial_content_len = asprintf(&initial_content,
+ "\n# tagging commit %s as %s\n",
+ commit_id_str, tag_name);
+ if (initial_content_len == -1) {
err = got_error_from_errno("asprintf");
goto done;
}
@@ -5660,7 +5665,7 @@ get_tag_message(char **tagmsg, char **tagmsg_path, const char *commit_id_str,
if (err)
goto done;
- dprintf(fd, initial_content);
+ write(fd, initial_content, initial_content_len);
close(fd);
err = get_editor(&editor);
@@ -6505,6 +6510,7 @@ collect_commit_logmsg(struct got_pathlist_head *commitable_paths, char **logmsg,
const struct got_error *err = NULL;
char *template = NULL;
struct collect_commit_logmsg_arg *a = arg;
+ int initial_content_len;
int fd;
size_t len;
@@ -6521,16 +6527,17 @@ collect_commit_logmsg(struct got_pathlist_head *commitable_paths, char **logmsg,
if (asprintf(&template, "%s/logmsg", a->worktree_path) == -1)
return got_error_from_errno("asprintf");
- if (asprintf(&initial_content,
+ initial_content_len = asprintf(&initial_content,
"\n# changes to be committed on branch %s:\n",
- a->branch_name) == -1)
+ a->branch_name);
+ if (initial_content_len == -1)
return got_error_from_errno("asprintf");
err = got_opentemp_named_fd(&a->logmsg_path, &fd, template);
if (err)
goto done;
- dprintf(fd, initial_content);
+ write(fd, initial_content, initial_content_len);
TAILQ_FOREACH(pe, commitable_paths, entry) {
struct got_commitable *ct = pe->data;
@@ -7715,6 +7722,7 @@ histedit_edit_logmsg(struct got_histedit_list_entry *hle,
char *logmsg = NULL, *new_msg = NULL, *editor = NULL;
const struct got_error *err = NULL;
struct got_commit_object *commit = NULL;
+ int logmsg_len;
int fd;
struct got_histedit_list_entry *folded = NULL;
@@ -7745,9 +7753,10 @@ histedit_edit_logmsg(struct got_histedit_list_entry *hle,
err = got_object_commit_get_logmsg(&orig_logmsg, commit);
if (err)
goto done;
- if (asprintf(&new_msg,
+ logmsg_len = asprintf(&new_msg,
"%s\n# original log message of commit %s: %s",
- logmsg ? logmsg : "", id_str, orig_logmsg) == -1) {
+ logmsg ? logmsg : "", id_str, orig_logmsg);
+ if (logmsg_len == -1) {
err = got_error_from_errno("asprintf");
goto done;
}
@@ -7763,7 +7772,7 @@ histedit_edit_logmsg(struct got_histedit_list_entry *hle,
if (err)
goto done;
- dprintf(fd, logmsg);
+ write(fd, logmsg, logmsg_len);
close(fd);
err = get_editor(&editor);