List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH 1/4] shared: remove return value from cgit_free_commitinfo()
@ 2016-08-13 11:04 john
  2016-08-13 11:04 ` [PATCH 2/4] shared: make cgit_free_taginfo() public john
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: john @ 2016-08-13 11:04 UTC (permalink / raw)


This return value is never used and the function always returns NULL.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 cgit.h   | 2 +-
 shared.c | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/cgit.h b/cgit.h
index 325432b..ec73dd3 100644
--- a/cgit.h
+++ b/cgit.h
@@ -343,7 +343,7 @@ extern void cgit_free_reflist_inner(struct reflist *list);
 extern int cgit_refs_cb(const char *refname, const struct object_id *oid,
 			int flags, void *cb_data);
 
-extern void *cgit_free_commitinfo(struct commitinfo *info);
+extern void cgit_free_commitinfo(struct commitinfo *info);
 
 void cgit_diff_tree_cb(struct diff_queue_struct *q,
 		       struct diff_options *options, void *data);
diff --git a/shared.c b/shared.c
index a63633b..432ce61 100644
--- a/shared.c
+++ b/shared.c
@@ -95,7 +95,7 @@ struct cgit_repo *cgit_get_repoinfo(const char *url)
 	return NULL;
 }
 
-void *cgit_free_commitinfo(struct commitinfo *info)
+void cgit_free_commitinfo(struct commitinfo *info)
 {
 	free(info->author);
 	free(info->author_email);
@@ -105,7 +105,6 @@ void *cgit_free_commitinfo(struct commitinfo *info)
 	free(info->msg);
 	free(info->msg_encoding);
 	free(info);
-	return NULL;
 }
 
 char *trim_end(const char *str, char c)
-- 
2.9.2.639.g855ae9f



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/4] shared: make cgit_free_taginfo() public
  2016-08-13 11:04 [PATCH 1/4] shared: remove return value from cgit_free_commitinfo() john
@ 2016-08-13 11:04 ` john
  2016-08-13 11:04 ` [PATCH 3/4] ui-tag: clean up taginfo john
  2016-08-13 11:04 ` [PATCH 4/4] ui-tree: remove a fixed size buffer john
  2 siblings, 0 replies; 4+ messages in thread
From: john @ 2016-08-13 11:04 UTC (permalink / raw)


We will use this function from ui-tag.c in the next patch.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 cgit.h   | 1 +
 shared.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/cgit.h b/cgit.h
index ec73dd3..c625161 100644
--- a/cgit.h
+++ b/cgit.h
@@ -344,6 +344,7 @@ extern int cgit_refs_cb(const char *refname, const struct object_id *oid,
 			int flags, void *cb_data);
 
 extern void cgit_free_commitinfo(struct commitinfo *info);
+extern void cgit_free_taginfo(struct taginfo *info);
 
 void cgit_diff_tree_cb(struct diff_queue_struct *q,
 		       struct diff_options *options, void *data);
diff --git a/shared.c b/shared.c
index 432ce61..15ccecf 100644
--- a/shared.c
+++ b/shared.c
@@ -203,7 +203,7 @@ static struct refinfo *cgit_mk_refinfo(const char *refname, const struct object_
 	return ref;
 }
 
-static void cgit_free_taginfo(struct taginfo *tag)
+void cgit_free_taginfo(struct taginfo *tag)
 {
 	if (tag->tagger)
 		free(tag->tagger);
-- 
2.9.2.639.g855ae9f



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/4] ui-tag: clean up taginfo
  2016-08-13 11:04 [PATCH 1/4] shared: remove return value from cgit_free_commitinfo() john
  2016-08-13 11:04 ` [PATCH 2/4] shared: make cgit_free_taginfo() public john
@ 2016-08-13 11:04 ` john
  2016-08-13 11:04 ` [PATCH 4/4] ui-tree: remove a fixed size buffer john
  2 siblings, 0 replies; 4+ messages in thread
From: john @ 2016-08-13 11:04 UTC (permalink / raw)


Free the taginfo when we're done with it.  Also reduce the scope of a
couple of variables so that it's clear that this is the only path that
uses the taginfo structure.

Coverity-Id: 141883
Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-tag.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/ui-tag.c b/ui-tag.c
index 6b838cb..3fa63b3 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -44,8 +44,6 @@ void cgit_print_tag(char *revname)
 	struct strbuf fullref = STRBUF_INIT;
 	unsigned char sha1[20];
 	struct object *obj;
-	struct tag *tag;
-	struct taginfo *info;
 
 	if (!revname)
 		revname = ctx.qry.head;
@@ -63,6 +61,9 @@ void cgit_print_tag(char *revname)
 		goto cleanup;
 	}
 	if (obj->type == OBJ_TAG) {
+		struct tag *tag;
+		struct taginfo *info;
+
 		tag = lookup_tag(sha1);
 		if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) {
 			cgit_print_error_page(500, "Internal server error",
@@ -99,6 +100,7 @@ void cgit_print_tag(char *revname)
 		html("</table>\n");
 		print_tag_content(info->msg);
 		cgit_print_layout_end();
+		cgit_free_taginfo(info);
 	} else {
 		cgit_print_layout_start();
 		html("<table class='commit-info'>\n");
-- 
2.9.2.639.g855ae9f



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 4/4] ui-tree: remove a fixed size buffer
  2016-08-13 11:04 [PATCH 1/4] shared: remove return value from cgit_free_commitinfo() john
  2016-08-13 11:04 ` [PATCH 2/4] shared: make cgit_free_taginfo() public john
  2016-08-13 11:04 ` [PATCH 3/4] ui-tag: clean up taginfo john
@ 2016-08-13 11:04 ` john
  2 siblings, 0 replies; 4+ messages in thread
From: john @ 2016-08-13 11:04 UTC (permalink / raw)


As libgit.a moves away from using fixed size buffers, there is no
guarantee that PATH_MAX is sufficient for all of the paths in a Git
tree, so we should use a dynamically sized buffer here.

Coverity-Id: 141884
Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-tree.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/ui-tree.c b/ui-tree.c
index 120066c..9966f75 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -258,22 +258,25 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base,
 		const char *pathname, unsigned mode, int stage, void *cbdata)
 {
 	struct walk_tree_context *walk_tree_ctx = cbdata;
-	static char buffer[PATH_MAX];
 
 	if (walk_tree_ctx->state == 0) {
-		memcpy(buffer, base->buf, base->len);
-		strcpy(buffer + base->len, pathname);
-		if (strcmp(walk_tree_ctx->match_path, buffer))
+		struct strbuf buffer = STRBUF_INIT;
+
+		strbuf_addbuf(&buffer, base);
+		strbuf_addstr(&buffer, pathname);
+		if (strcmp(walk_tree_ctx->match_path, buffer.buf))
 			return READ_TREE_RECURSIVE;
 
 		if (S_ISDIR(mode)) {
 			walk_tree_ctx->state = 1;
-			set_title_from_path(buffer);
+			set_title_from_path(buffer.buf);
+			strbuf_release(&buffer);
 			ls_head();
 			return READ_TREE_RECURSIVE;
 		} else {
 			walk_tree_ctx->state = 2;
-			print_object(sha1, buffer, pathname, walk_tree_ctx->curr_rev);
+			print_object(sha1, buffer.buf, pathname, walk_tree_ctx->curr_rev);
+			strbuf_release(&buffer);
 			return 0;
 		}
 	}
-- 
2.9.2.639.g855ae9f



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-08-13 11:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-13 11:04 [PATCH 1/4] shared: remove return value from cgit_free_commitinfo() john
2016-08-13 11:04 ` [PATCH 2/4] shared: make cgit_free_taginfo() public john
2016-08-13 11:04 ` [PATCH 3/4] ui-tag: clean up taginfo john
2016-08-13 11:04 ` [PATCH 4/4] ui-tree: remove a fixed size buffer john

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).