[PATCH] upload-pack: fix sparse warnings
Signed-off-by: Ramsay Jones --- Hi Jonathan, If you need to re-roll your 'jt/fetch-cdn-offload' branch, could you please squash this into the relevant patches. (The first hunk into commit a8d662e3da4 ("upload-pack: refactor reading of pack-objects out", 2019-03-08) and the second hunk into commit 820a5361db1 ("upload-pack: send part of packfile response as uri", 2019,-03-08)). [Johannes mentioned 'clang' complaining - I have clang v5.0.1 and it does not issue any warnings for the new initialization.] This patch fixes the following sparse warnings: $ diff psp-out psp-out1 190,191d189 < upload-pack.c:182:45: warning: missing braces around initializer < upload-pack.c:1167:56: warning: Using plain integer as NULL pointer $ If you don't like the new initializer expression, maybe don't initialize in the declaration and use a traditional: memset(&output_state, 0, sizeof(struct output_state)); instead? Thanks! ATB, Ramsay Jones upload-pack.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index d36e1fc06a..52309d40ae 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -179,7 +179,7 @@ static void create_pack_file(const struct object_array *have_obj, const struct string_list *uri_protocols) { struct child_process pack_objects = CHILD_PROCESS_INIT; - struct output_state output_state = {0}; + struct output_state output_state = { { 0 }, 0, 0, 0 }; char progress[128]; char abort_msg[] = "aborting due to possible repository " "corruption on the remote side."; @@ -1164,7 +1164,7 @@ void upload_pack(struct upload_pack_options *options) if (want_obj.nr) { struct object_array have_obj = OBJECT_ARRAY_INIT; get_common_commits(&reader, &have_obj, &want_obj); - create_pack_file(&have_obj, &want_obj, 0); + create_pack_file(&have_obj, &want_obj, NULL); } } -- 2.21.0
Re: [PATCH] revision.c: fix sparse warnings (sparse algorithm)
Derrick Stolee writes: > On 1/13/2019 3:55 PM, Ramsay Jones wrote: >> Signed-off-by: Ramsay Jones >> --- >> >> Hi Derrick, >> >> If you need to re-roll your 'ds/push-sparse-tree-walk' branch, could >> you please squash this into the relevant patch [commit 9949aaeef4 >> ("revision: implement sparse algorithm", 2018-12-14)]. >> >> This commit caused both 'sparse' and my 'static-check.pl' script to >> complain about the visibility of the 'map_flags' variable (it is a >> file local variable), so one solution would be to mark it 'static'. >> However, it is simply not being used, so ... >> >> Thanks! >> >> ATB, >> Ramsay Jones > > Thanks, Ramsay! I'm rerolling the series today, so I will make this change. > > -Stolee Thanks, both.
Re: [PATCH] revision.c: fix sparse warnings (sparse algorithm)
On 1/13/2019 3:55 PM, Ramsay Jones wrote: Signed-off-by: Ramsay Jones --- Hi Derrick, If you need to re-roll your 'ds/push-sparse-tree-walk' branch, could you please squash this into the relevant patch [commit 9949aaeef4 ("revision: implement sparse algorithm", 2018-12-14)]. This commit caused both 'sparse' and my 'static-check.pl' script to complain about the visibility of the 'map_flags' variable (it is a file local variable), so one solution would be to mark it 'static'. However, it is simply not being used, so ... Thanks! ATB, Ramsay Jones Thanks, Ramsay! I'm rerolling the series today, so I will make this change. -Stolee
[PATCH] revision.c: fix sparse warnings (sparse algorithm)
Signed-off-by: Ramsay Jones --- Hi Derrick, If you need to re-roll your 'ds/push-sparse-tree-walk' branch, could you please squash this into the relevant patch [commit 9949aaeef4 ("revision: implement sparse algorithm", 2018-12-14)]. This commit caused both 'sparse' and my 'static-check.pl' script to complain about the visibility of the 'map_flags' variable (it is a file local variable), so one solution would be to mark it 'static'. However, it is simply not being used, so ... Thanks! ATB, Ramsay Jones revision.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/revision.c b/revision.c index a048da3cf5..c4982a70b1 100644 --- a/revision.c +++ b/revision.c @@ -114,10 +114,9 @@ static int path_and_oids_cmp(const void *hashmap_cmp_fn_data, return strcmp(e1->path, e2->path); } -int map_flags = 0; static void paths_and_oids_init(struct hashmap *map) { - hashmap_init(map, (hashmap_cmp_fn) path_and_oids_cmp, &map_flags, 0); + hashmap_init(map, (hashmap_cmp_fn) path_and_oids_cmp, NULL, 0); } static void paths_and_oids_clear(struct hashmap *map) -- 2.20.0
[PATCH] line-log: Fix sparse warnings
Sparse issues the following warnings: line-log.c:17:6: warning: symbol 'range_set_grow' was not declared. Should it be static? line-log.c:25:6: warning: symbol 'range_set_init' was not declared. Should it be static? line-log.c:33:6: warning: symbol 'range_set_release' was not declared. Should it be static? line-log.c:41:6: warning: symbol 'range_set_copy' was not declared. Should it be static? line-log.c:47:6: warning: symbol 'range_set_move' was not declared. Should it be static? line-log.c:58:6: warning: symbol 'range_set_append' was not declared. Should it be static? line-log.c:299:46: warning: Using plain integer as NULL pointer line-log.c:444:12: warning: symbol 'parse_loc' was not declared. Should it be static? line-log.c:681:49: warning: Using plain integer as NULL pointer line-log.c:684:58: warning: Using plain integer as NULL pointer builtin/log.c:120:57: warning: Using plain integer as NULL pointer builtin/log.c:120:60: warning: Using plain integer as NULL pointer In order to suppress the "... was not declared" warnings, we simply add the static modifier to the declarations of those symbols, since they do not need more than file scope. In order to suppress the "NULL pointer" warnings, we simply replace the use of the integer constant zero as a representation of the null pointer with the NULL symbol. Signed-off-by: Ramsay Jones --- Hi Thomas, If you need to re-roll the patches in your 'tr/line-log' branch, could you please squash these changes in. [Note that this patch applies to the tip of the pu branch ;-) ] Also, I noticed some things in passing, viz: 971 static void load_tree_desc(struct tree_desc *desc, void **tree, 972 const unsigned char *sha1) 973 { 974 unsigned long size; 975 *tree = read_object_with_reference(sha1, tree_type, &size, NULL); 976 if (!tree) 977 die("Unable to read tree (%s)", sha1_to_hex(sha1)); 978 init_tree_desc(desc, *tree, size); 979 } The die() on line 977 will never trigger, since (given that !tree holds) we will already have dumped core on line 975! ;-) 1401 int line_log_filter(struct rev_info *rev) 1402 { 1403 struct commit *commit; 1404 struct commit_list *list = rev->commits; 1405 struct commit_list *out = NULL, *cur = NULL; 1406 1407 list = rev->commits; 1408 while (list) { Note that the assignment on line 1407 is redundant and can be removed; list has been initialized to the same value in it's declaration on line 1404. HTH ATB, Ramsay Jones builtin/log.c | 2 +- line-log.c| 20 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index c5d2313..a551d8d 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -117,7 +117,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, { struct userformat_want w; int quiet = 0, source = 0, mailmap = 0; - static struct line_opt_callback_data line_cb = {0, 0, STRING_LIST_INIT_DUP}; + static struct line_opt_callback_data line_cb = {NULL, NULL, STRING_LIST_INIT_DUP}; const struct option builtin_log_options[] = { OPT_BOOLEAN(0, "quiet", &quiet, N_("suppress diff output")), diff --git a/line-log.c b/line-log.c index a74bbaf..4d01798 100644 --- a/line-log.c +++ b/line-log.c @@ -14,7 +14,7 @@ #include "userdiff.h" #include "line-log.h" -void range_set_grow (struct range_set *rs, size_t extra) +static void range_set_grow (struct range_set *rs, size_t extra) { ALLOC_GROW(rs->ranges, rs->nr + extra, rs->alloc); } @@ -22,7 +22,7 @@ void range_set_grow (struct range_set *rs, size_t extra) /* Either initialization would be fine */ #define RANGE_SET_INIT {0} -void range_set_init (struct range_set *rs, size_t prealloc) +static void range_set_init (struct range_set *rs, size_t prealloc) { rs->alloc = rs->nr = 0; rs->ranges = NULL; @@ -30,7 +30,7 @@ void range_set_init (struct range_set *rs, size_t prealloc) range_set_grow(rs, prealloc); } -void range_set_release (struct range_set *rs) +static void range_set_release (struct range_set *rs) { free(rs->ranges); rs->alloc = rs->nr = 0; @@ -38,13 +38,13 @@ void range_set_release (struct range_set *rs) } /* dst must be uninitialized! */ -void range_set_copy (struct range_set *dst, struct range_set *src) +static void range_set_copy (struct range_set *dst, struct range_set *src) { range_set_init(dst, src->nr); memcpy(dst->ranges, src->ranges, src->nr*sizeof(struct range_set)); dst->nr = src->nr; } -void range_set_move (struct range_set *dst, struct range_set *src) +static void range_set_move (struct range_set *dst, struct range_set *src) { range_set_release(dst); dst->ranges = src->ranges; @@ -55,7 +55,7
[Patch] Fix sparse warnings
fix one 'should it be static?' warning and two 'mixing declarations and code' warnings. Signed-off-by: Alecs King <[EMAIL PROTECTED]> --- connect.c|3 ++- ssh-pull.c |2 +- tools/mailinfo.c |2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/connect.c b/connect.c --- a/connect.c +++ b/connect.c @@ -219,6 +219,7 @@ static struct ref *find_ref_by_name(stru int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, int nr_refspec, char **refspec, int all) { + int len; struct refspec *rs = parse_ref_spec(nr_refspec, refspec); if (nr_refspec) @@ -236,7 +237,7 @@ int match_refs(struct ref *src, struct r if (!all) continue; /* Create a new one and link it */ - int len = strlen(src->name) + 1; + len = strlen(src->name) + 1; dst_peer = xcalloc(1, sizeof(*dst_peer) + len); memcpy(dst_peer->name, src->name, len); memcpy(dst_peer->new_sha1, src->new_sha1, 20); diff --git a/ssh-pull.c b/ssh-pull.c --- a/ssh-pull.c +++ b/ssh-pull.c @@ -10,7 +10,7 @@ static int fd_out; static unsigned char remote_version = 0; static unsigned char local_version = 1; -ssize_t force_write(int fd, void *buffer, size_t length) +static ssize_t force_write(int fd, void *buffer, size_t length) { ssize_t ret = 0; while (ret < length) { diff --git a/tools/mailinfo.c b/tools/mailinfo.c --- a/tools/mailinfo.c +++ b/tools/mailinfo.c @@ -152,13 +152,13 @@ static void cleanup_space(char *buf) static void handle_rest(void) { + FILE *out = cmitmsg; char *sub = cleanup_subject(subject); cleanup_space(name); cleanup_space(date); cleanup_space(email); cleanup_space(sub); printf("Author: %s\nEmail: %s\nSubject: %s\nDate: %s\n\n", name, email, sub, date); - FILE *out = cmitmsg; do { if (!memcmp("diff -", line, 6) || -- Alecs King - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
Fix sparse warnings
A few sparse warnings have crept in again since I checked last time: undeclared variables with global scope. Fix them by marking the private variables properly "static". Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]> Btw, sparse also warns about the "return 0" in receive-pack.c: unpack(), since that function is supposed to return void. I think somebody else already sent a patch for that one. diff --git a/daemon.c b/daemon.c --- a/daemon.c +++ b/daemon.c @@ -71,13 +71,13 @@ static int max_connections = 25; /* These are updated by the signal handler */ static volatile unsigned int children_reaped = 0; -pid_t dead_child[MAX_CHILDREN]; +static pid_t dead_child[MAX_CHILDREN]; /* These are updated by the main loop */ static unsigned int children_spawned = 0; static unsigned int children_deleted = 0; -struct child { +static struct child { pid_t pid; socklen_t addrlen; struct sockaddr_storage address; diff --git a/rev-cache.c b/rev-cache.c --- a/rev-cache.c +++ b/rev-cache.c @@ -5,7 +5,7 @@ struct rev_cache **rev_cache; int nr_revs, alloc_revs; -struct rev_list_elem *rle_free; +static struct rev_list_elem *rle_free; #define BATCH_SIZE 512 diff --git a/server-info.c b/server-info.c --- a/server-info.c +++ b/server-info.c @@ -62,7 +62,7 @@ static int update_info_refs(int force) } /* packs */ -struct pack_info { +static struct pack_info { unsigned long latest; struct packed_git *p; int old_num; - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html