Commit a0de39f3978b1d152679279d6e2f82d573e81209

Stefan Sperling 2019-08-09T11:56:24

fix build on OpenBSD/sparc64 (gcc)

diff --git a/got/got.c b/got/got.c
index 48602a4..7042801 100644
--- a/got/got.c
+++ b/got/got.c
@@ -1083,7 +1083,7 @@ static const struct got_error *
 get_worktree_paths_from_argv(struct got_pathlist_head *paths, int argc,
     char *argv[], struct got_worktree *worktree)
 {
-	const struct got_error *err;
+	const struct got_error *err = NULL;
 	char *path;
 	int i;
 
@@ -4647,6 +4647,8 @@ histedit_check_script(struct got_histedit_list *histedit_cmds,
 	if (TAILQ_EMPTY(histedit_cmds))
 		return got_error_msg(GOT_ERR_EMPTY_HISTEDIT,
 		    "histedit script contains no commands");
+	if (SIMPLEQ_EMPTY(commits))
+		return got_error(GOT_ERR_EMPTY_HISTEDIT);
 
 	SIMPLEQ_FOREACH(qid, commits, entry) {
 		TAILQ_FOREACH(hle, histedit_cmds, entry) {
diff --git a/lib/blame.c b/lib/blame.c
index eda1af0..e00d1af 100644
--- a/lib/blame.c
+++ b/lib/blame.c
@@ -413,8 +413,10 @@ done:
 static const struct got_error *
 blame_line(struct got_object_id **id, struct got_blame *blame, int lineno)
 {
-	if (lineno < 1 || lineno > blame->nlines)
+	if (lineno < 1 || lineno > blame->nlines) {
+		*id = NULL;
 		return got_error(GOT_ERR_RANGE);
+	}
 	*id = &blame->lines[lineno - 1].id;
 	return NULL;
 }
@@ -452,7 +454,7 @@ got_blame(const char *path, struct got_object_id *start_commit_id,
 	}
 
 	for (lineno = 1; lineno <= blame->nlines; lineno++) {
-		struct got_object_id *id;
+		struct got_object_id *id = NULL;
 		char *line, *id_str;
 
 		line = parse_next_line(blame->f, NULL);
diff --git a/lib/object_cache.c b/lib/object_cache.c
index 0c1a60f..6d87621 100644
--- a/lib/object_cache.c
+++ b/lib/object_cache.c
@@ -157,6 +157,8 @@ got_object_cache_add(struct got_object_cache *cache, struct got_object_id *id, v
 	case GOT_OBJECT_CACHE_TYPE_TAG:
 		size = get_size_tag((struct got_tag_object *)item);
 		break;
+	default:
+		return got_error(GOT_ERR_OBJ_TYPE);
 	}
 
 	if (size > GOT_OBJECT_CACHE_MAX_ELEM_SIZE) {
diff --git a/lib/object_parse.c b/lib/object_parse.c
index bbf3289..a7eb8cd 100644
--- a/lib/object_parse.c
+++ b/lib/object_parse.c
@@ -608,6 +608,8 @@ parse_tree_entry(struct got_tree_entry **te, size_t *elen, char *buf,
 	char *p, *space;
 	const struct got_error *err = NULL;
 
+	*elen = 0;
+
 	*te = got_alloc_tree_entry_partial();
 	if (*te == NULL)
 		return got_error_from_errno("got_alloc_tree_entry_partial");
diff --git a/lib/pack.c b/lib/pack.c
index d9d0f11..06a6211 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -628,6 +628,7 @@ parse_negative_offset(int64_t *offset, size_t *len, struct got_pack *pack,
 	uint8_t offN;
 	int i = 0;
 
+	*offset = 0;
 	*len = 0;
 
 	do {
diff --git a/lib/worktree.c b/lib/worktree.c
index 58f47bc..d648267 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2363,7 +2363,7 @@ read_ignores(struct got_pathlist_head *ignores, const char *path, FILE *f)
 	const struct got_error *err = NULL;
 	struct got_pathlist_entry *pe = NULL;
 	struct got_pathlist_head *ignorelist;
-	char *line = NULL, *pattern, *dirpath;
+	char *line = NULL, *pattern, *dirpath = NULL;
 	size_t linesize = 0;
 	ssize_t linelen;
 
diff --git a/tog/tog.c b/tog/tog.c
index 210e39c..f6655ba 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -3980,6 +3980,8 @@ blame_tree_entry(struct tog_view **new_view, int begin_x,
 	char *path;
 	struct tog_view *blame_view;
 
+	*new_view = NULL;
+
 	err = tree_entry_path(&path, parents, te);
 	if (err)
 		return err;
@@ -4007,6 +4009,8 @@ log_tree_entry(struct tog_view **new_view, int begin_x,
 	const struct got_error *err = NULL;
 	char *path;
 
+	*new_view = NULL;
+
 	log_view = view_open(0, 0, 0, begin_x, TOG_VIEW_LOG);
 	if (log_view == NULL)
 		return got_error_from_errno("view_open");
@@ -4113,7 +4117,7 @@ static const struct got_error *
 search_next_tree_view(struct tog_view *view)
 {
 	struct tog_tree_view_state *s = &view->state.tree;
-	struct got_tree_entry *entry, *te;
+	struct got_tree_entry *entry = NULL, *te;
 
 	if (!view->searching) {
 		view->search_next_done = 1;