@matheusbsbs / matheus-bagliano / commits / 2af202be3d
Fork 0

Fix various sparse warnings in the git source code

There are a few remaining ones, but this fixes the trivial ones. It boils down to two main issues that sparse complains about: - warning: Using plain integer as NULL pointer Sparse doesn't like you using '0' instead of 'NULL'. For various good reasons, not the least of which is just the visual confusion. A NULL pointer is not an integer, and that whole "0 works as NULL" is a historical accident and not very pretty. A few of these remain: zlib is a total mess, and Z_NULL is just a 0. I didn't touch those. - warning: symbol 'xyz' was not declared. Should it be static? Sparse wants to see declarations for any functions you export. A lack of a declaration tends to mean that you should either add one, or you should mark the function 'static' to show that it's in file scope. A few of these remain: I only did the ones that should obviously just be made static. That 'wt_status_submodule_summary' one is debatable. It has a few related flags (like 'wt_status_use_color') which _are_ declared, and are used by builtin-commit.c. So maybe we'd like to export it at some point, but it's not declared now, and not used outside of that file, so 'static' it is in this patch. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Jun 18, 2009 at 10:28 UTC 2af202be3d2f128c6974290cabe13179c6462196
23 files changed +42 -42
bisect.c
+2 -2
@@ -454,7 +454,7 @@ static int read_bisect_refs(void)
454 return for_each_ref_in("refs/bisect/", register_ref, NULL);
455 }
456
457 -void read_bisect_paths(struct argv_array *array)
457 +static void read_bisect_paths(struct argv_array *array)
458 {
459 struct strbuf str = STRBUF_INIT;
460 const char *filename = git_path("BISECT_NAMES");
@@ -780,7 +780,7 @@ static void handle_bad_merge_base(void)
780 exit(1);
781 }
782
783 -void handle_skipped_merge_base(const unsigned char *mb)
783 +static void handle_skipped_merge_base(const unsigned char *mb)
784 {
785 char *mb_hex = sha1_to_hex(mb);
786 char *bad_hex = sha1_to_hex(current_bad_sha1);
builtin-add.c
+1 -1
@@ -189,7 +189,7 @@ int interactive_add(int argc, const char **argv, const char *prefix)
189 return status;
190 }
191
192 -int edit_patch(int argc, const char **argv, const char *prefix)
192 +static int edit_patch(int argc, const char **argv, const char *prefix)
193 {
194 char *file = xstrdup(git_path("ADD_EDIT.patch"));
195 const char *apply_argv[] = { "apply", "--recount", "--cached",
builtin-apply.c
+1 -1
@@ -2614,7 +2614,7 @@ static int get_current_sha1(const char *path, unsigned char *sha1)
2614 static void build_fake_ancestor(struct patch *list, const char *filename)
2615 {
2616 struct patch *patch;
2617 - struct index_state result = { 0 };
2617 + struct index_state result = { NULL };
2618 int fd;
2619
2620 /* Once we start supporting the reverse patch, it may be
builtin-clone.c
+1 -1
@@ -141,7 +141,7 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
141 if (is_bare) {
142 struct strbuf result = STRBUF_INIT;
143 strbuf_addf(&result, "%.*s.git", (int)(end - start), start);
144 - dir = strbuf_detach(&result, 0);
144 + dir = strbuf_detach(&result, NULL);
145 } else
146 dir = xstrndup(start, end - start);
147 /*
builtin-fsck.c
+2 -2
@@ -104,7 +104,7 @@ static int mark_object(struct object *obj, int type, void *data)
104
105 static void mark_object_reachable(struct object *obj)
106 {
107 - mark_object(obj, OBJ_ANY, 0);
107 + mark_object(obj, OBJ_ANY, NULL);
108 }
109
110 static int traverse_one_object(struct object *obj, struct object *parent)
@@ -292,7 +292,7 @@ static int fsck_sha1(const unsigned char *sha1)
292 fprintf(stderr, "Checking %s %s\n",
293 typename(obj->type), sha1_to_hex(obj->sha1));
294
295 - if (fsck_walk(obj, mark_used, 0))
295 + if (fsck_walk(obj, mark_used, NULL))
296 objerror(obj, "broken links");
297 if (fsck_object(obj, check_strict, fsck_error_func))
298 return -1;
builtin-help.c
+1 -1
@@ -394,7 +394,7 @@ static void get_html_page_path(struct strbuf *page_path, const char *page)
394 * HTML.
395 */
396 #ifndef open_html
397 -void open_html(const char *path)
397 +static void open_html(const char *path)
398 {
399 execl_git_cmd("web--browse", "-c", "help.browser", path, NULL);
400 }
builtin-log.c
+2 -2
@@ -94,7 +94,7 @@ static void show_early_header(struct rev_info *rev, const char *stage, int nr)
94 printf("Final output: %d %s\n", nr, stage);
95 }
96
97 -struct itimerval early_output_timer;
97 +static struct itimerval early_output_timer;
98
99 static void log_show_early(struct rev_info *revs, struct commit_list *list)
100 {
@@ -977,7 +977,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
977 strbuf_addch(&buf, '\n');
978 }
979
980 - rev.extra_headers = strbuf_detach(&buf, 0);
980 + rev.extra_headers = strbuf_detach(&buf, NULL);
981
982 if (start_number < 0)
983 start_number = 1;
builtin-merge.c
+2 -2
@@ -370,7 +370,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
370
371 strbuf_addstr(&buf, "refs/heads/");
372 strbuf_addstr(&buf, remote);
373 - resolve_ref(buf.buf, branch_head, 0, 0);
373 + resolve_ref(buf.buf, branch_head, 0, NULL);
374
375 if (!hashcmp(remote_head->sha1, branch_head)) {
376 strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
@@ -409,7 +409,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
409 strbuf_addstr(&truname, "refs/heads/");
410 strbuf_addstr(&truname, remote);
411 strbuf_setlen(&truname, truname.len - len);
412 - if (resolve_ref(truname.buf, buf_sha, 0, 0)) {
412 + if (resolve_ref(truname.buf, buf_sha, 0, NULL)) {
413 strbuf_addf(msg,
414 "%s\t\tbranch '%s'%s of .\n",
415 sha1_to_hex(remote_head->sha1),
builtin-remote.c
+8 -8
@@ -740,7 +740,7 @@ static int rm(int argc, const char **argv)
740 return result;
741 }
742
743 -void clear_push_info(void *util, const char *string)
743 +static void clear_push_info(void *util, const char *string)
744 {
745 struct push_info *info = util;
746 free(info->dest);
@@ -815,7 +815,7 @@ struct show_info {
815 int any_rebase;
816 };
817
818 -int add_remote_to_show_info(struct string_list_item *item, void *cb_data)
818 +static int add_remote_to_show_info(struct string_list_item *item, void *cb_data)
819 {
820 struct show_info *info = cb_data;
821 int n = strlen(item->string);
@@ -825,7 +825,7 @@ int add_remote_to_show_info(struct string_list_item *item, void *cb_data)
825 return 0;
826 }
827
828 -int show_remote_info_item(struct string_list_item *item, void *cb_data)
828 +static int show_remote_info_item(struct string_list_item *item, void *cb_data)
829 {
830 struct show_info *info = cb_data;
831 struct ref_states *states = info->states;
@@ -852,7 +852,7 @@ int show_remote_info_item(struct string_list_item *item, void *cb_data)
852 return 0;
853 }
854
855 -int add_local_to_show_info(struct string_list_item *branch_item, void *cb_data)
855 +static int add_local_to_show_info(struct string_list_item *branch_item, void *cb_data)
856 {
857 struct show_info *show_info = cb_data;
858 struct ref_states *states = show_info->states;
@@ -874,7 +874,7 @@ int add_local_to_show_info(struct string_list_item *branch_item, void *cb_data)
874 return 0;
875 }
876
877 -int show_local_info_item(struct string_list_item *item, void *cb_data)
877 +static int show_local_info_item(struct string_list_item *item, void *cb_data)
878 {
879 struct show_info *show_info = cb_data;
880 struct branch_info *branch_info = item->util;
@@ -906,7 +906,7 @@ int show_local_info_item(struct string_list_item *item, void *cb_data)
906 return 0;
907 }
908
909 -int add_push_to_show_info(struct string_list_item *push_item, void *cb_data)
909 +static int add_push_to_show_info(struct string_list_item *push_item, void *cb_data)
910 {
911 struct show_info *show_info = cb_data;
912 struct push_info *push_info = push_item->util;
@@ -935,7 +935,7 @@ static int cmp_string_with_push(const void *va, const void *vb)
935 return cmp ? cmp : strcmp(a_push->dest, b_push->dest);
936 }
937
938 -int show_push_info_item(struct string_list_item *item, void *cb_data)
938 +static int show_push_info_item(struct string_list_item *item, void *cb_data)
939 {
940 struct show_info *show_info = cb_data;
941 struct push_info *push_info = item->util;
@@ -1197,7 +1197,7 @@ static int get_one_remote_for_update(struct remote *remote, void *priv)
1197 return 0;
1198 }
1199
1200 -struct remote_group {
1200 +static struct remote_group {
1201 const char *name;
1202 struct string_list *list;
1203 } remote_group;
builtin-unpack-objects.c
+3 -3
@@ -158,7 +158,7 @@ struct obj_info {
158 #define FLAG_WRITTEN (1u<<21)
159
160 static struct obj_info *obj_list;
161 -unsigned nr_objects;
161 +static unsigned nr_objects;
162
163 /*
164 * Called only from check_object() after it verified this object
@@ -200,7 +200,7 @@ static int check_object(struct object *obj, int type, void *data)
200
201 if (fsck_object(obj, 1, fsck_error_function))
202 die("Error in object");
203 - if (!fsck_walk(obj, check_object, 0))
203 + if (!fsck_walk(obj, check_object, NULL))
204 die("Error on reachable objects of %s", sha1_to_hex(obj->sha1));
205 write_cached_object(obj);
206 return 1;
@@ -210,7 +210,7 @@ static void write_rest(void)
210 {
211 unsigned i;
212 for (i = 0; i < nr_objects; i++)
213 - check_object(obj_list[i].obj, OBJ_ANY, 0);
213 + check_object(obj_list[i].obj, OBJ_ANY, NULL);
214 }
215
216 static void added_object(unsigned nr, enum object_type type,
connect.c
+1 -1
@@ -464,7 +464,7 @@ static void git_proxy_connect(int fd[2], char *host)
464
465 #define MAX_CMD_LEN 1024
466
467 -char *get_port(char *host)
467 +static char *get_port(char *host)
468 {
469 char *end;
470 char *p = strchr(host, ':');
daemon.c
+1 -1
@@ -453,7 +453,7 @@ static void parse_host_arg(char *extra_args, int buflen)
453 memset(&hints, 0, sizeof(hints));
454 hints.ai_flags = AI_CANONNAME;
455
456 - gai = getaddrinfo(hostname, 0, &hints, &ai);
456 + gai = getaddrinfo(hostname, NULL, &hints, &ai);
457 if (!gai) {
458 struct sockaddr_in *sin_addr = (void *)ai->ai_addr;
459
http-push.c
+1 -1
@@ -1750,7 +1750,7 @@ static int delete_remote_branch(char *pattern, int force)
1750 return 0;
1751 }
1752
1753 -void run_request_queue(void)
1753 +static void run_request_queue(void)
1754 {
1755 #ifdef USE_CURL_MULTI
1756 is_running_queue = 1;
imap-send.c
+1 -1
@@ -238,7 +238,7 @@ static const char *Flags[] = {
238 #ifndef NO_OPENSSL
239 static void ssl_socket_perror(const char *func)
240 {
241 - fprintf(stderr, "%s: %s\n", func, ERR_error_string(ERR_get_error(), 0));
241 + fprintf(stderr, "%s: %s\n", func, ERR_error_string(ERR_get_error(), NULL));
242 }
243 #endif
244
index-pack.c
+1 -1
@@ -469,7 +469,7 @@ static void sha1_object(const void *data, unsigned long size,
469 die("invalid %s", typename(type));
470 if (fsck_object(obj, 1, fsck_error_function))
471 die("Error in object");
472 - if (fsck_walk(obj, mark_link, 0))
472 + if (fsck_walk(obj, mark_link, NULL))
473 die("Not all child objects of %s are reachable", sha1_to_hex(obj->sha1));
474
475 if (obj->type == OBJ_TREE) {
mailmap.c
+3 -3
@@ -103,7 +103,7 @@ static char *parse_name_and_email(char *buffer, char **name,
103 char **email, int allow_empty_email)
104 {
105 char *left, *right, *nstart, *nend;
106 - *name = *email = 0;
106 + *name = *email = NULL;
107
108 if ((left = strchr(buffer, '<')) == NULL)
109 return NULL;
@@ -136,7 +136,7 @@ static int read_single_mailmap(struct string_list *map, const char *filename, ch
136 if (f == NULL)
137 return 1;
138 while (fgets(buffer, sizeof(buffer), f) != NULL) {
139 - char *name1 = 0, *email1 = 0, *name2 = 0, *email2 = 0;
139 + char *name1 = NULL, *email1 = NULL, *name2 = NULL, *email2 = NULL;
140 if (buffer[0] == '#') {
141 static const char abbrev[] = "# repo-abbrev:";
142 int abblen = sizeof(abbrev) - 1;
@@ -200,7 +200,7 @@ int map_user(struct string_list *map,
200 if (!p) {
201 /* email passed in might not be wrapped in <>, but end with a \0 */
202 p = memchr(email, '\0', maxlen_email);
203 - if (p == 0)
203 + if (!p)
204 return 0;
205 }
206 if (p - email + 1 < sizeof(buf))
merge-recursive.c
+1 -1
@@ -38,7 +38,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two)
38 * A virtual commit has (const char *)commit->util set to the name.
39 */
40
41 -struct commit *make_virtual_commit(struct tree *tree, const char *comment)
41 +static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
42 {
43 struct commit *commit = xcalloc(1, sizeof(struct commit));
44 commit->tree = tree;
parse-options.c
+1 -1
@@ -478,7 +478,7 @@ static int usage_argh(const struct option *opts)
478 #define USAGE_OPTS_WIDTH 24
479 #define USAGE_GAP 2
480
481 -int usage_with_options_internal(const char * const *usagestr,
481 +static int usage_with_options_internal(const char * const *usagestr,
482 const struct option *opts, int full)
483 {
484 if (!usagestr)
quote.c
+2 -2
@@ -272,8 +272,8 @@ void write_name_quoted(const char *name, FILE *fp, int terminator)
272 fputc(terminator, fp);
273 }
274
275 -extern void write_name_quotedpfx(const char *pfx, size_t pfxlen,
276 - const char *name, FILE *fp, int terminator)
275 +void write_name_quotedpfx(const char *pfx, size_t pfxlen,
276 + const char *name, FILE *fp, int terminator)
277 {
278 int needquote = 0;
279
remote.c
+3 -3
@@ -307,7 +307,7 @@ static void read_branches_file(struct remote *remote)
307 strbuf_addstr(&branch, "HEAD:");
308 }
309 add_url_alias(remote, p);
310 - add_fetch_refspec(remote, strbuf_detach(&branch, 0));
310 + add_fetch_refspec(remote, strbuf_detach(&branch, NULL));
311 /*
312 * Cogito compatible push: push current HEAD to remote #branch
313 * (master if missing)
@@ -318,7 +318,7 @@ static void read_branches_file(struct remote *remote)
318 strbuf_addf(&branch, ":refs/heads/%s", frag);
319 else
320 strbuf_addstr(&branch, ":refs/heads/master");
321 - add_push_refspec(remote, strbuf_detach(&branch, 0));
321 + add_push_refspec(remote, strbuf_detach(&branch, NULL));
322 remote->fetch_tags = 1; /* always auto-follow */
323 }
324
@@ -1119,7 +1119,7 @@ int match_refs(struct ref *src, struct ref **dst,
1119 int send_all = flags & MATCH_REFS_ALL;
1120 int send_mirror = flags & MATCH_REFS_MIRROR;
1121 int errs;
1122 - static const char *default_refspec[] = { ":", 0 };
1122 + static const char *default_refspec[] = { ":", NULL };
1123 struct ref **dst_tail = tail_ref(dst);
1124
1125 if (!nr_refspec) {
test-parse-options.c
+2 -2
@@ -9,7 +9,7 @@ static int verbose = 0, dry_run = 0, quiet = 0;
9 static char *string = NULL;
10 static char *file = NULL;
11
12 -int length_callback(const struct option *opt, const char *arg, int unset)
12 +static int length_callback(const struct option *opt, const char *arg, int unset)
13 {
14 printf("Callback: \"%s\", %d\n",
15 (arg ? arg : "not set"), unset);
@@ -20,7 +20,7 @@ int length_callback(const struct option *opt, const char *arg, int unset)
20 return 0;
21 }
22
23 -int number_callback(const struct option *opt, const char *arg, int unset)
23 +static int number_callback(const struct option *opt, const char *arg, int unset)
24 {
25 *(int *)opt->value = strtol(arg, NULL, 10);
26 return 0;
unpack-trees.c
+1 -1
@@ -140,7 +140,7 @@ static int unpack_index_entry(struct cache_entry *ce, struct unpack_trees_option
140 return call_unpack_fn(src, o);
141 }
142
143 -int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long df_conflicts, struct name_entry *names, struct traverse_info *info)
143 +static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long df_conflicts, struct name_entry *names, struct traverse_info *info)
144 {
145 int i;
146 struct tree_desc t[MAX_UNPACK_TREES];
wt-status.c
+1 -1
@@ -13,7 +13,7 @@
13
14 int wt_status_relative_paths = 1;
15 int wt_status_use_color = -1;
16 -int wt_status_submodule_summary;
16 +static int wt_status_submodule_summary;
17 static char wt_status_colors[][COLOR_MAXLEN] = {
18 GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
19 GIT_COLOR_GREEN, /* WT_STATUS_UPDATED */