List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH 00/13] Fixes for problems detected by Sparse
@ 2015-03-08 16:32 john
  2015-03-08 16:32 ` [PATCH 01/13] Makefile: add a target to run CGit through sparse john
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: john @ 2015-03-08 16:32 UTC (permalink / raw)


Sparse[0] detects several potential problems in CGit, which are all
fixed by this set of patches.  Most of these are style issues that are
correct either way (using integer zero as a NULL pointer), but I think
there is value in keeping the build clean of Sparse warnings.


[0] https://sparse.wiki.kernel.org/index.php/Main_Page

John Keeping (13):
  Makefile: add a target to run CGit through sparse
  Avoid non-ANSI function declarations
  Avoid signed bitfields
  scan-tree: make some variables 'static'
  shared: make some variables 'static'
  ui-log: make some variables 'static'
  ui-repolist: make sortcolumn definitions 'static const'
  ui-shared: make cgit_doctype 'static'
  ui-stats: make cgit_period definitions 'static const'
  ui-shared: avoid initializing static variable to zero
  ui-shared: don't use an integer as a NULL pointer
  cache: don't use an integer as a NULL pointer
  html: avoid using a plain integer as a NULL pointer

 Makefile      |  3 +++
 cache.c       |  2 +-
 cgit.c        |  2 +-
 cgit.mk       |  9 ++++++++-
 filter.c      |  2 +-
 html.c        | 54 ++++++++++++++++++++++++++++++++----------------------
 scan-tree.c   |  4 ++--
 shared.c      |  4 ++--
 ui-blob.c     |  4 ++--
 ui-diff.c     |  4 ++--
 ui-log.c      |  2 +-
 ui-refs.c     |  4 ++--
 ui-repolist.c | 10 +++++-----
 ui-shared.c   | 18 +++++++++---------
 ui-ssdiff.c   | 16 ++++++++--------
 ui-stats.c    | 14 +++++++-------
 ui-stats.h    |  2 +-
 ui-summary.c  |  2 +-
 ui-tree.c     |  4 ++--
 19 files changed, 90 insertions(+), 70 deletions(-)

-- 
2.3.1.308.g754cd77



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

* [PATCH 01/13] Makefile: add a target to run CGit through sparse
  2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
@ 2015-03-08 16:32 ` john
  2015-03-08 16:32 ` [PATCH 02/13] Avoid non-ANSI function declarations john
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: john @ 2015-03-08 16:32 UTC (permalink / raw)


Signed-off-by: John Keeping <john at keeping.me.uk>
---
 Makefile | 3 +++
 cgit.mk  | 9 ++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index ed329e8..42ed230 100644
--- a/Makefile
+++ b/Makefile
@@ -68,6 +68,9 @@ all:: cgit
 cgit:
 	$(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) -f ../cgit.mk ../cgit $(EXTRA_GIT_TARGETS) NO_CURL=1
 
+sparse:
+	$(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) -f ../cgit.mk NO_CURL=1 cgit-sparse
+
 test:
 	@$(MAKE) --no-print-directory cgit EXTRA_GIT_TARGETS=all
 	$(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all
diff --git a/cgit.mk b/cgit.mk
index 5048b09..1b50307 100644
--- a/cgit.mk
+++ b/cgit.mk
@@ -96,7 +96,7 @@ CGIT_OBJS := $(addprefix $(CGIT_PREFIX),$(CGIT_OBJ_NAMES))
 
 # Only cgit.c reference CGIT_VERSION so we only rebuild its objects when the
 # version changes.
-CGIT_VERSION_OBJS := $(addprefix $(CGIT_PREFIX),cgit.o)
+CGIT_VERSION_OBJS := $(addprefix $(CGIT_PREFIX),cgit.o cgit.sp)
 $(CGIT_VERSION_OBJS): $(CGIT_PREFIX)VERSION
 $(CGIT_VERSION_OBJS): EXTRA_CPPFLAGS = \
 	-DCGIT_VERSION='"$(CGIT_VERSION)"'
@@ -129,3 +129,10 @@ $(CGIT_OBJS): %.o: %.c GIT-CFLAGS $(CGIT_PREFIX)CGIT-CFLAGS $(missing_dep_dirs)
 $(CGIT_PREFIX)cgit: $(CGIT_OBJS) GIT-LDFLAGS $(GITLIBS)
 	@echo 1>&1 "    * $(LUA_MESSAGE)"
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) $(CGIT_LIBS)
+
+CGIT_SP_OBJS := $(patsubst %.o,%.sp,$(CGIT_OBJS))
+
+$(CGIT_SP_OBJS): %.sp: %.c GIT-CFLAGS $(CGIT_PREFIX)CGIT-CFLAGS FORCE
+	$(QUIET_SP)cgcc -no-compile $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $(SPARSE_FLAGS) $<
+
+cgit-sparse: $(CGIT_SP_OBJS)
-- 
2.3.1.308.g754cd77



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

* [PATCH 02/13] Avoid non-ANSI function declarations
  2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
  2015-03-08 16:32 ` [PATCH 01/13] Makefile: add a target to run CGit through sparse john
@ 2015-03-08 16:32 ` john
  2015-03-08 16:32 ` [PATCH 03/13] Avoid signed bitfields john
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: john @ 2015-03-08 16:32 UTC (permalink / raw)


Sparse says things like:

	warning: non-ANSI function declaration of function 'calc_ttl'

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 cgit.c        |  2 +-
 filter.c      |  2 +-
 ui-diff.c     |  2 +-
 ui-refs.c     |  4 ++--
 ui-repolist.c |  6 +++---
 ui-shared.c   | 12 ++++++------
 ui-ssdiff.c   | 16 ++++++++--------
 ui-summary.c  |  2 +-
 ui-tree.c     |  4 ++--
 9 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/cgit.c b/cgit.c
index 0ad8171..c16ed8c 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1013,7 +1013,7 @@ static void cgit_parse_args(int argc, const char **argv)
 	}
 }
 
-static int calc_ttl()
+static int calc_ttl(void)
 {
 	if (!ctx.repo)
 		return ctx.cfg.cache_root_ttl;
diff --git a/filter.c b/filter.c
index 9f433db..ebf4937 100644
--- a/filter.c
+++ b/filter.c
@@ -72,7 +72,7 @@ static inline void hook_write(struct cgit_filter *filter, ssize_t (*new_write)(s
 	filter_write = new_write;
 }
 
-static inline void unhook_write()
+static inline void unhook_write(void)
 {
 	assert(filter_write != NULL);
 	assert(current_write_filter != NULL);
diff --git a/ui-diff.c b/ui-diff.c
index 5b6df1f..8eff178 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -311,7 +311,7 @@ static void filepair_cb(struct diff_filepair *pair)
 		cgit_ssdiff_footer();
 }
 
-void cgit_print_diff_ctrls()
+void cgit_print_diff_ctrls(void)
 {
 	int i, curr;
 
diff --git a/ui-refs.c b/ui-refs.c
index ac8a6d4..d3d71dd 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -82,7 +82,7 @@ static int print_branch(struct refinfo *ref)
 	return 0;
 }
 
-static void print_tag_header()
+static void print_tag_header(void)
 {
 	html("<tr class='nohover'><th class='left'>Tag</th>"
 	     "<th class='left'>Download</th>"
@@ -234,7 +234,7 @@ void cgit_print_tags(int maxcount)
 	cgit_free_reflist_inner(&list);
 }
 
-void cgit_print_refs()
+void cgit_print_refs(void)
 {
 
 	html("<table class='list nowrap'>");
diff --git a/ui-repolist.c b/ui-repolist.c
index e945f67..a6d0321 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -117,7 +117,7 @@ static void print_sort_header(const char *title, const char *sort)
 	htmlf("'>%s</a></th>", title);
 }
 
-static void print_header()
+static void print_header(void)
 {
 	html("<tr class='nohover'>");
 	print_sort_header("Name", "name");
@@ -247,7 +247,7 @@ static int sort_repolist(char *field)
 }
 
 
-void cgit_print_repolist()
+void cgit_print_repolist(void)
 {
 	int i, columns = 3, hits = 0, header = 0;
 	char *last_section = NULL;
@@ -344,7 +344,7 @@ void cgit_print_repolist()
 	cgit_print_docend();
 }
 
-void cgit_print_site_readme()
+void cgit_print_site_readme(void)
 {
 	if (!ctx.cfg.root_readme)
 		return;
diff --git a/ui-shared.c b/ui-shared.c
index ff03cb2..6d3cfa9 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -46,7 +46,7 @@ void cgit_vprint_error(const char *fmt, va_list ap)
 	html("</div>\n");
 }
 
-const char *cgit_httpscheme()
+const char *cgit_httpscheme(void)
 {
 	if (ctx.env.https && !strcmp(ctx.env.https, "on"))
 		return "https://";
@@ -54,7 +54,7 @@ const char *cgit_httpscheme()
 		return "http://";
 }
 
-const char *cgit_hosturl()
+const char *cgit_hosturl(void)
 {
 	if (ctx.env.http_host)
 		return ctx.env.http_host;
@@ -65,14 +65,14 @@ const char *cgit_hosturl()
 	return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port);
 }
 
-const char *cgit_currenturl()
+const char *cgit_currenturl(void)
 {
 	if (!ctx.qry.url)
 		return cgit_rooturl();
 	return ctx.qry.url;
 }
 
-const char *cgit_rooturl()
+const char *cgit_rooturl(void)
 {
 	if (ctx.cfg.virtual_root)
 		return ctx.cfg.virtual_root;
@@ -80,7 +80,7 @@ const char *cgit_rooturl()
 		return ctx.cfg.script_name;
 }
 
-const char *cgit_loginurl()
+const char *cgit_loginurl(void)
 {
 	static const char *login_url = 0;
 	if (!login_url)
@@ -735,7 +735,7 @@ void cgit_print_docstart(void)
 		html_include(ctx.cfg.header);
 }
 
-void cgit_print_docend()
+void cgit_print_docend(void)
 {
 	html("</div> <!-- class=content -->\n");
 	if (ctx.cfg.embedded) {
diff --git a/ui-ssdiff.c b/ui-ssdiff.c
index 08cf513..2146c71 100644
--- a/ui-ssdiff.c
+++ b/ui-ssdiff.c
@@ -18,7 +18,7 @@ struct deferred_lines {
 static struct deferred_lines *deferred_old, *deferred_old_last;
 static struct deferred_lines *deferred_new, *deferred_new_last;
 
-static void create_or_reset_lcs_table()
+static void create_or_reset_lcs_table(void)
 {
 	int i;
 
@@ -276,7 +276,7 @@ static void print_ssdiff_line(char *class,
 		free(old_line);
 }
 
-static void print_deferred_old_lines()
+static void print_deferred_old_lines(void)
 {
 	struct deferred_lines *iter_old, *tmp;
 	iter_old = deferred_old;
@@ -289,7 +289,7 @@ static void print_deferred_old_lines()
 	}
 }
 
-static void print_deferred_new_lines()
+static void print_deferred_new_lines(void)
 {
 	struct deferred_lines *iter_new, *tmp;
 	iter_new = deferred_new;
@@ -302,7 +302,7 @@ static void print_deferred_new_lines()
 	}
 }
 
-static void print_deferred_changed_lines()
+static void print_deferred_changed_lines(void)
 {
 	struct deferred_lines *iter_old, *iter_new, *tmp;
 	int n_old_lines = calc_deferred_lines(deferred_old);
@@ -337,7 +337,7 @@ static void print_deferred_changed_lines()
 	}
 }
 
-void cgit_ssdiff_print_deferred_lines()
+void cgit_ssdiff_print_deferred_lines(void)
 {
 	if (!deferred_old && !deferred_new)
 		return;
@@ -388,7 +388,7 @@ void cgit_ssdiff_line_cb(char *line, int len)
 	line[len - 1] = c;
 }
 
-void cgit_ssdiff_header_begin()
+void cgit_ssdiff_header_begin(void)
 {
 	current_old_line = -1;
 	current_new_line = -1;
@@ -396,12 +396,12 @@ void cgit_ssdiff_header_begin()
 	html("<tr><td class='head' colspan='4'>");
 }
 
-void cgit_ssdiff_header_end()
+void cgit_ssdiff_header_end(void)
 {
 	html("</td><tr>");
 }
 
-void cgit_ssdiff_footer()
+void cgit_ssdiff_footer(void)
 {
 	if (deferred_old || deferred_new)
 		cgit_ssdiff_print_deferred_lines();
diff --git a/ui-summary.c b/ui-summary.c
index fa5ba04..b0af073 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -40,7 +40,7 @@ static void print_url(const char *url)
 	html("</a></td></tr>\n");
 }
 
-void cgit_print_summary()
+void cgit_print_summary(void)
 {
 	int columns = 3;
 
diff --git a/ui-tree.c b/ui-tree.c
index 4ab0137..bbc468e 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -180,7 +180,7 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base,
 	return 0;
 }
 
-static void ls_head()
+static void ls_head(void)
 {
 	html("<table summary='tree listing' class='list'>\n");
 	html("<tr class='nohover'>");
@@ -191,7 +191,7 @@ static void ls_head()
 	html("</tr>\n");
 }
 
-static void ls_tail()
+static void ls_tail(void)
 {
 	html("</table>\n");
 }
-- 
2.3.1.308.g754cd77



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

* [PATCH 03/13] Avoid signed bitfields
  2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
  2015-03-08 16:32 ` [PATCH 01/13] Makefile: add a target to run CGit through sparse john
  2015-03-08 16:32 ` [PATCH 02/13] Avoid non-ANSI function declarations john
@ 2015-03-08 16:32 ` john
  2015-03-08 16:32 ` [PATCH 04/13] scan-tree: make some variables 'static' john
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: john @ 2015-03-08 16:32 UTC (permalink / raw)


Bitfields are only defined for unsigned types.

Detected by sparse.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-blob.c | 4 ++--
 ui-diff.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/ui-blob.c b/ui-blob.c
index a025bca..388a017 100644
--- a/ui-blob.c
+++ b/ui-blob.c
@@ -14,8 +14,8 @@
 struct walk_tree_context {
 	const char *match_path;
 	unsigned char *matched_sha1;
-	int found_path:1;
-	int file_only:1;
+	unsigned int found_path:1;
+	unsigned int file_only:1;
 };
 
 static int walk_tree(const unsigned char *sha1, struct strbuf *base,
diff --git a/ui-diff.c b/ui-diff.c
index 8eff178..1cf2ce0 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -31,7 +31,7 @@ static struct fileinfo {
 	unsigned int removed;
 	unsigned long old_size;
 	unsigned long new_size;
-	int binary:1;
+	unsigned int binary:1;
 } *items;
 
 static int use_ssdiff = 0;
-- 
2.3.1.308.g754cd77



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

* [PATCH 04/13] scan-tree: make some variables 'static'
  2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
                   ` (2 preceding siblings ...)
  2015-03-08 16:32 ` [PATCH 03/13] Avoid signed bitfields john
@ 2015-03-08 16:32 ` john
  2015-03-08 16:32 ` [PATCH 05/13] shared: " john
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: john @ 2015-03-08 16:32 UTC (permalink / raw)


These are not used outside this file and are not declared.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 scan-tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scan-tree.c b/scan-tree.c
index e900ad9..8e3cf52 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -45,8 +45,8 @@ out:
 	return result;
 }
 
-struct cgit_repo *repo;
-repo_config_fn config_fn;
+static struct cgit_repo *repo;
+static repo_config_fn config_fn;
 
 static void repo_config(const char *name, const char *value)
 {
-- 
2.3.1.308.g754cd77



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

* [PATCH 05/13] shared: make some variables 'static'
  2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
                   ` (3 preceding siblings ...)
  2015-03-08 16:32 ` [PATCH 04/13] scan-tree: make some variables 'static' john
@ 2015-03-08 16:32 ` john
  2015-03-08 16:32 ` [PATCH 06/13] ui-log: " john
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: john @ 2015-03-08 16:32 UTC (permalink / raw)


These are not used outside this file and are not declared.

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

diff --git a/shared.c b/shared.c
index ae17d78..a99173b 100644
--- a/shared.c
+++ b/shared.c
@@ -284,8 +284,8 @@ static int load_mmfile(mmfile_t *file, const unsigned char *sha1)
  * ripped from git and modified to use globals instead of
  * a special callback-struct.
  */
-char *diffbuf = NULL;
-int buflen = 0;
+static char *diffbuf = NULL;
+static int buflen = 0;
 
 static int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf)
 {
-- 
2.3.1.308.g754cd77



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

* [PATCH 06/13] ui-log: make some variables 'static'
  2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
                   ` (4 preceding siblings ...)
  2015-03-08 16:32 ` [PATCH 05/13] shared: " john
@ 2015-03-08 16:32 ` john
  2015-03-08 16:32 ` [PATCH 07/13] ui-repolist: make sortcolumn definitions 'static const' john
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: john @ 2015-03-08 16:32 UTC (permalink / raw)


These are not used outside this file and are not declared.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui-log.c b/ui-log.c
index 1b60591..32b4c47 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -12,7 +12,7 @@
 #include "ui-shared.h"
 #include "argv-array.h"
 
-int files, add_lines, rem_lines;
+static int files, add_lines, rem_lines;
 
 /*
  * The list of available column colors in the commit graph.
-- 
2.3.1.308.g754cd77



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

* [PATCH 07/13] ui-repolist: make sortcolumn definitions 'static const'
  2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
                   ` (5 preceding siblings ...)
  2015-03-08 16:32 ` [PATCH 06/13] ui-log: " john
@ 2015-03-08 16:32 ` john
  2015-03-08 16:32 ` [PATCH 08/13] ui-shared: make cgit_doctype 'static' john
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: john @ 2015-03-08 16:32 UTC (permalink / raw)


These are not used outside this file and are not declared; they are also
never modified.

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

diff --git a/ui-repolist.c b/ui-repolist.c
index a6d0321..2453a7f 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -223,7 +223,7 @@ struct sortcolumn {
 	int (*fn)(const void *a, const void *b);
 };
 
-struct sortcolumn sortcolumn[] = {
+static const struct sortcolumn sortcolumn[] = {
 	{"section", sort_section},
 	{"name", sort_name},
 	{"desc", sort_desc},
@@ -234,7 +234,7 @@ struct sortcolumn sortcolumn[] = {
 
 static int sort_repolist(char *field)
 {
-	struct sortcolumn *column;
+	const struct sortcolumn *column;
 
 	for (column = &sortcolumn[0]; column->name; column++) {
 		if (strcmp(field, column->name))
-- 
2.3.1.308.g754cd77



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

* [PATCH 08/13] ui-shared: make cgit_doctype 'static'
  2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
                   ` (6 preceding siblings ...)
  2015-03-08 16:32 ` [PATCH 07/13] ui-repolist: make sortcolumn definitions 'static const' john
@ 2015-03-08 16:32 ` john
  2015-03-08 16:32 ` [PATCH 09/13] ui-stats: make cgit_period definitions 'static const' john
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: john @ 2015-03-08 16:32 UTC (permalink / raw)


This is not used outside this file and is not declared.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-shared.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui-shared.c b/ui-shared.c
index 6d3cfa9..d4c4bb9 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -11,7 +11,7 @@
 #include "cmd.h"
 #include "html.h"
 
-const char cgit_doctype[] =
+static const char cgit_doctype[] =
 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
 "  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
 
-- 
2.3.1.308.g754cd77



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

* [PATCH 09/13] ui-stats: make cgit_period definitions 'static const'
  2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
                   ` (7 preceding siblings ...)
  2015-03-08 16:32 ` [PATCH 08/13] ui-shared: make cgit_doctype 'static' john
@ 2015-03-08 16:32 ` john
  2015-03-08 16:32 ` [PATCH 10/13] ui-shared: avoid initializing static variable to zero john
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: john @ 2015-03-08 16:32 UTC (permalink / raw)


These definitions should not be modified (and never are) so we can move
them to .rodata.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-stats.c | 14 +++++++-------
 ui-stats.h |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/ui-stats.c b/ui-stats.c
index a264f6a..9cd8247 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -125,7 +125,7 @@ static char *pretty_year(struct tm *tm)
 	return fmt("%d", tm->tm_year + 1900);
 }
 
-struct cgit_period periods[] = {
+static const struct cgit_period periods[] = {
 	{'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week},
 	{'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month},
 	{'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter},
@@ -136,7 +136,7 @@ struct cgit_period periods[] = {
  * and update the period pointer to the correcsponding struct.
  * If no matching code is found, return 0.
  */
-int cgit_find_stats_period(const char *expr, struct cgit_period **period)
+int cgit_find_stats_period(const char *expr, const struct cgit_period **period)
 {
 	int i;
 	char code = '\0';
@@ -165,7 +165,7 @@ const char *cgit_find_stats_periodname(int idx)
 }
 
 static void add_commit(struct string_list *authors, struct commit *commit,
-	struct cgit_period *period)
+	const struct cgit_period *period)
 {
 	struct commitinfo *info;
 	struct string_list_item *author, *item;
@@ -209,7 +209,7 @@ static int cmp_total_commits(const void *a1, const void *a2)
 /* Walk the commit DAG and collect number of commits per author per
  * timeperiod into a nested string_list collection.
  */
-static struct string_list collect_stats(struct cgit_period *period)
+static struct string_list collect_stats(const struct cgit_period *period)
 {
 	struct string_list authors;
 	struct rev_info rev;
@@ -256,7 +256,7 @@ static void print_combined_authorrow(struct string_list *authors, int from,
 				     const char *leftclass,
 				     const char *centerclass,
 				     const char *rightclass,
-				     struct cgit_period *period)
+				     const struct cgit_period *period)
 {
 	struct string_list_item *author;
 	struct authorstat *authorstat;
@@ -295,7 +295,7 @@ static void print_combined_authorrow(struct string_list *authors, int from,
 }
 
 static void print_authors(struct string_list *authors, int top,
-			  struct cgit_period *period)
+			  const struct cgit_period *period)
 {
 	struct string_list_item *author;
 	struct authorstat *authorstat;
@@ -363,7 +363,7 @@ static void print_authors(struct string_list *authors, int top,
 void cgit_show_stats(void)
 {
 	struct string_list authors;
-	struct cgit_period *period;
+	const struct cgit_period *period;
 	int top, i;
 	const char *code = "w";
 
diff --git a/ui-stats.h b/ui-stats.h
index 341ab13..0e61b03 100644
--- a/ui-stats.h
+++ b/ui-stats.h
@@ -20,7 +20,7 @@ struct cgit_period {
 	char *(*pretty)(struct tm *tm);
 };
 
-extern int cgit_find_stats_period(const char *expr, struct cgit_period **period);
+extern int cgit_find_stats_period(const char *expr, const struct cgit_period **period);
 extern const char *cgit_find_stats_periodname(int idx);
 
 extern void cgit_show_stats(void);
-- 
2.3.1.308.g754cd77



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

* [PATCH 10/13] ui-shared: avoid initializing static variable to zero
  2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
                   ` (8 preceding siblings ...)
  2015-03-08 16:32 ` [PATCH 09/13] ui-stats: make cgit_period definitions 'static const' john
@ 2015-03-08 16:32 ` john
  2015-03-08 16:32 ` [PATCH 11/13] ui-shared: don't use an integer as a NULL pointer john
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: john @ 2015-03-08 16:32 UTC (permalink / raw)


Sparse complains that we are using a plain integer as a NULL pointer
here, but in fact we do not have to specify a value for this variable at
all since it has static storage duration and thus will be initialized to
NULL by the compiler.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-shared.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui-shared.c b/ui-shared.c
index d4c4bb9..1e3c131 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -82,7 +82,7 @@ const char *cgit_rooturl(void)
 
 const char *cgit_loginurl(void)
 {
-	static const char *login_url = 0;
+	static const char *login_url;
 	if (!login_url)
 		login_url = fmtalloc("%s?p=login", cgit_rooturl());
 	return login_url;
-- 
2.3.1.308.g754cd77



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

* [PATCH 11/13] ui-shared: don't use an integer as a NULL pointer
  2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
                   ` (9 preceding siblings ...)
  2015-03-08 16:32 ` [PATCH 10/13] ui-shared: avoid initializing static variable to zero john
@ 2015-03-08 16:32 ` john
  2015-03-08 16:32 ` [PATCH 12/13] cache: " john
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: john @ 2015-03-08 16:32 UTC (permalink / raw)


Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-shared.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui-shared.c b/ui-shared.c
index 1e3c131..7bcb8d3 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -119,7 +119,7 @@ char *cgit_fileurl(const char *reponame, const char *pagename,
 char *cgit_pageurl(const char *reponame, const char *pagename,
 		   const char *query)
 {
-	return cgit_fileurl(reponame, pagename, 0, query);
+	return cgit_fileurl(reponame, pagename, NULL, query);
 }
 
 const char *cgit_repobasename(const char *reponame)
-- 
2.3.1.308.g754cd77



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

* [PATCH 12/13] cache: don't use an integer as a NULL pointer
  2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
                   ` (10 preceding siblings ...)
  2015-03-08 16:32 ` [PATCH 11/13] ui-shared: don't use an integer as a NULL pointer john
@ 2015-03-08 16:32 ` john
  2015-03-08 16:32 ` [PATCH 13/13] html: avoid using a plain " john
  2015-03-09 16:41 ` [PATCH 00/13] Fixes for problems detected by Sparse Jason
  13 siblings, 0 replies; 15+ messages in thread
From: john @ 2015-03-08 16:32 UTC (permalink / raw)


Signed-off-by: John Keeping <john at keeping.me.uk>
---
 cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cache.c b/cache.c
index 900b161..cd99812 100644
--- a/cache.c
+++ b/cache.c
@@ -411,7 +411,7 @@ int cache_ls(const char *path)
 	DIR *dir;
 	struct dirent *ent;
 	int err = 0;
-	struct cache_slot slot = { 0 };
+	struct cache_slot slot = { NULL };
 	struct strbuf fullname = STRBUF_INIT;
 	size_t prefixlen;
 
-- 
2.3.1.308.g754cd77



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

* [PATCH 13/13] html: avoid using a plain integer as a NULL pointer
  2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
                   ` (11 preceding siblings ...)
  2015-03-08 16:32 ` [PATCH 12/13] cache: " john
@ 2015-03-08 16:32 ` john
  2015-03-09 16:41 ` [PATCH 00/13] Fixes for problems detected by Sparse Jason
  13 siblings, 0 replies; 15+ messages in thread
From: john @ 2015-03-08 16:32 UTC (permalink / raw)


Sparse complains about this table because we use the integer zero as the
NULL pointer.  Use this as an opportunity to reformat the table so that
it always contains 8 elements per row, making it easier to see which
values are being set and which are not.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 html.c | 54 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 32 insertions(+), 22 deletions(-)

diff --git a/html.c b/html.c
index f0ee2d6..155cde5 100644
--- a/html.c
+++ b/html.c
@@ -17,28 +17,38 @@
 
 /* Percent-encoding of each character, except: a-zA-Z0-9!$()*,./:;@- */
 static const char* url_escape_table[256] = {
-	"%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09",
-	"%0a", "%0b", "%0c", "%0d", "%0e", "%0f", "%10", "%11", "%12", "%13",
-	"%14", "%15", "%16", "%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d",
-	"%1e", "%1f", "%20", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0,
-	"%2b", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%3c", "%3d",
-	"%3e", "%3f", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, "%5c", 0, "%5e", 0, "%60", 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%7b",
-	"%7c", "%7d", 0, "%7f", "%80", "%81", "%82", "%83", "%84", "%85",
-	"%86", "%87", "%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f",
-	"%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97", "%98", "%99",
-	"%9a", "%9b", "%9c", "%9d", "%9e", "%9f", "%a0", "%a1", "%a2", "%a3",
-	"%a4", "%a5", "%a6", "%a7", "%a8", "%a9", "%aa", "%ab", "%ac", "%ad",
-	"%ae", "%af", "%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7",
-	"%b8", "%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf", "%c0", "%c1",
-	"%c2", "%c3", "%c4", "%c5", "%c6", "%c7", "%c8", "%c9", "%ca", "%cb",
-	"%cc", "%cd", "%ce", "%cf", "%d0", "%d1", "%d2", "%d3", "%d4", "%d5",
-	"%d6", "%d7", "%d8", "%d9", "%da", "%db", "%dc", "%dd", "%de", "%df",
-	"%e0", "%e1", "%e2", "%e3", "%e4", "%e5", "%e6", "%e7", "%e8", "%e9",
-	"%ea", "%eb", "%ec", "%ed", "%ee", "%ef", "%f0", "%f1", "%f2", "%f3",
-	"%f4", "%f5", "%f6", "%f7", "%f8", "%f9", "%fa", "%fb", "%fc", "%fd",
-	"%fe", "%ff"
+	"%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
+	"%08", "%09", "%0a", "%0b", "%0c", "%0d", "%0e", "%0f",
+	"%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",
+	"%18", "%19", "%1a", "%1b", "%1c", "%1d", "%1e", "%1f",
+	"%20", NULL,  "%22", "%23", NULL,  "%25", "%26", "%27",
+	NULL,  NULL,  NULL,  "%2b", NULL,  NULL,  NULL,  NULL,
+	NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,
+	NULL,  NULL,  NULL,  NULL,  "%3c", "%3d", "%3e", "%3f",
+	NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,
+	NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,
+	NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,
+	NULL,  NULL,  NULL,  NULL,  "%5c", NULL,  "%5e", NULL,
+	"%60", NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,
+	NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,
+	NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,
+	NULL,  NULL,  NULL,  "%7b", "%7c", "%7d", NULL,  "%7f",
+	"%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87",
+	"%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f",
+	"%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97",
+	"%98", "%99", "%9a", "%9b", "%9c", "%9d", "%9e", "%9f",
+	"%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%a6", "%a7",
+	"%a8", "%a9", "%aa", "%ab", "%ac", "%ad", "%ae", "%af",
+	"%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7",
+	"%b8", "%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf",
+	"%c0", "%c1", "%c2", "%c3", "%c4", "%c5", "%c6", "%c7",
+	"%c8", "%c9", "%ca", "%cb", "%cc", "%cd", "%ce", "%cf",
+	"%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7",
+	"%d8", "%d9", "%da", "%db", "%dc", "%dd", "%de", "%df",
+	"%e0", "%e1", "%e2", "%e3", "%e4", "%e5", "%e6", "%e7",
+	"%e8", "%e9", "%ea", "%eb", "%ec", "%ed", "%ee", "%ef",
+	"%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
+	"%f8", "%f9", "%fa", "%fb", "%fc", "%fd", "%fe", "%ff"
 };
 
 char *fmt(const char *format, ...)
-- 
2.3.1.308.g754cd77



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

* [PATCH 00/13] Fixes for problems detected by Sparse
  2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
                   ` (12 preceding siblings ...)
  2015-03-08 16:32 ` [PATCH 13/13] html: avoid using a plain " john
@ 2015-03-09 16:41 ` Jason
  13 siblings, 0 replies; 15+ messages in thread
From: Jason @ 2015-03-09 16:41 UTC (permalink / raw)


Great idea. Merged. Thanks John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20150309/74c0bb04/attachment.html>


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

end of thread, other threads:[~2015-03-09 16:41 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-08 16:32 [PATCH 00/13] Fixes for problems detected by Sparse john
2015-03-08 16:32 ` [PATCH 01/13] Makefile: add a target to run CGit through sparse john
2015-03-08 16:32 ` [PATCH 02/13] Avoid non-ANSI function declarations john
2015-03-08 16:32 ` [PATCH 03/13] Avoid signed bitfields john
2015-03-08 16:32 ` [PATCH 04/13] scan-tree: make some variables 'static' john
2015-03-08 16:32 ` [PATCH 05/13] shared: " john
2015-03-08 16:32 ` [PATCH 06/13] ui-log: " john
2015-03-08 16:32 ` [PATCH 07/13] ui-repolist: make sortcolumn definitions 'static const' john
2015-03-08 16:32 ` [PATCH 08/13] ui-shared: make cgit_doctype 'static' john
2015-03-08 16:32 ` [PATCH 09/13] ui-stats: make cgit_period definitions 'static const' john
2015-03-08 16:32 ` [PATCH 10/13] ui-shared: avoid initializing static variable to zero john
2015-03-08 16:32 ` [PATCH 11/13] ui-shared: don't use an integer as a NULL pointer john
2015-03-08 16:32 ` [PATCH 12/13] cache: " john
2015-03-08 16:32 ` [PATCH 13/13] html: avoid using a plain " john
2015-03-09 16:41 ` [PATCH 00/13] Fixes for problems detected by Sparse Jason

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).