Skip to content

Commit 2af202b

Browse files
torvaldsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a49eb19 commit 2af202b

23 files changed

+42
-42
lines changed

bisect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ static int read_bisect_refs(void)
454454
return for_each_ref_in("refs/bisect/", register_ref, NULL);
455455
}
456456

457-
void read_bisect_paths(struct argv_array *array)
457+
static void read_bisect_paths(struct argv_array *array)
458458
{
459459
struct strbuf str = STRBUF_INIT;
460460
const char *filename = git_path("BISECT_NAMES");
@@ -780,7 +780,7 @@ static void handle_bad_merge_base(void)
780780
exit(1);
781781
}
782782

783-
void handle_skipped_merge_base(const unsigned char *mb)
783+
static void handle_skipped_merge_base(const unsigned char *mb)
784784
{
785785
char *mb_hex = sha1_to_hex(mb);
786786
char *bad_hex = sha1_to_hex(current_bad_sha1);

builtin-add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ int interactive_add(int argc, const char **argv, const char *prefix)
189189
return status;
190190
}
191191

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)
193193
{
194194
char *file = xstrdup(git_path("ADD_EDIT.patch"));
195195
const char *apply_argv[] = { "apply", "--recount", "--cached",

builtin-apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2614,7 +2614,7 @@ static int get_current_sha1(const char *path, unsigned char *sha1)
26142614
static void build_fake_ancestor(struct patch *list, const char *filename)
26152615
{
26162616
struct patch *patch;
2617-
struct index_state result = { 0 };
2617+
struct index_state result = { NULL };
26182618
int fd;
26192619

26202620
/* Once we start supporting the reverse patch, it may be

builtin-clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
141141
if (is_bare) {
142142
struct strbuf result = STRBUF_INIT;
143143
strbuf_addf(&result, "%.*s.git", (int)(end - start), start);
144-
dir = strbuf_detach(&result, 0);
144+
dir = strbuf_detach(&result, NULL);
145145
} else
146146
dir = xstrndup(start, end - start);
147147
/*

builtin-fsck.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static int mark_object(struct object *obj, int type, void *data)
104104

105105
static void mark_object_reachable(struct object *obj)
106106
{
107-
mark_object(obj, OBJ_ANY, 0);
107+
mark_object(obj, OBJ_ANY, NULL);
108108
}
109109

110110
static int traverse_one_object(struct object *obj, struct object *parent)
@@ -292,7 +292,7 @@ static int fsck_sha1(const unsigned char *sha1)
292292
fprintf(stderr, "Checking %s %s\n",
293293
typename(obj->type), sha1_to_hex(obj->sha1));
294294

295-
if (fsck_walk(obj, mark_used, 0))
295+
if (fsck_walk(obj, mark_used, NULL))
296296
objerror(obj, "broken links");
297297
if (fsck_object(obj, check_strict, fsck_error_func))
298298
return -1;

builtin-help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ static void get_html_page_path(struct strbuf *page_path, const char *page)
394394
* HTML.
395395
*/
396396
#ifndef open_html
397-
void open_html(const char *path)
397+
static void open_html(const char *path)
398398
{
399399
execl_git_cmd("web--browse", "-c", "help.browser", path, NULL);
400400
}

builtin-log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void show_early_header(struct rev_info *rev, const char *stage, int nr)
9494
printf("Final output: %d %s\n", nr, stage);
9595
}
9696

97-
struct itimerval early_output_timer;
97+
static struct itimerval early_output_timer;
9898

9999
static void log_show_early(struct rev_info *revs, struct commit_list *list)
100100
{
@@ -977,7 +977,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
977977
strbuf_addch(&buf, '\n');
978978
}
979979

980-
rev.extra_headers = strbuf_detach(&buf, 0);
980+
rev.extra_headers = strbuf_detach(&buf, NULL);
981981

982982
if (start_number < 0)
983983
start_number = 1;

builtin-merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
370370

371371
strbuf_addstr(&buf, "refs/heads/");
372372
strbuf_addstr(&buf, remote);
373-
resolve_ref(buf.buf, branch_head, 0, 0);
373+
resolve_ref(buf.buf, branch_head, 0, NULL);
374374

375375
if (!hashcmp(remote_head->sha1, branch_head)) {
376376
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
@@ -409,7 +409,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
409409
strbuf_addstr(&truname, "refs/heads/");
410410
strbuf_addstr(&truname, remote);
411411
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)) {
413413
strbuf_addf(msg,
414414
"%s\t\tbranch '%s'%s of .\n",
415415
sha1_to_hex(remote_head->sha1),

builtin-remote.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ static int rm(int argc, const char **argv)
740740
return result;
741741
}
742742

743-
void clear_push_info(void *util, const char *string)
743+
static void clear_push_info(void *util, const char *string)
744744
{
745745
struct push_info *info = util;
746746
free(info->dest);
@@ -815,7 +815,7 @@ struct show_info {
815815
int any_rebase;
816816
};
817817

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)
819819
{
820820
struct show_info *info = cb_data;
821821
int n = strlen(item->string);
@@ -825,7 +825,7 @@ int add_remote_to_show_info(struct string_list_item *item, void *cb_data)
825825
return 0;
826826
}
827827

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)
829829
{
830830
struct show_info *info = cb_data;
831831
struct ref_states *states = info->states;
@@ -852,7 +852,7 @@ int show_remote_info_item(struct string_list_item *item, void *cb_data)
852852
return 0;
853853
}
854854

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)
856856
{
857857
struct show_info *show_info = cb_data;
858858
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)
874874
return 0;
875875
}
876876

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)
878878
{
879879
struct show_info *show_info = cb_data;
880880
struct branch_info *branch_info = item->util;
@@ -906,7 +906,7 @@ int show_local_info_item(struct string_list_item *item, void *cb_data)
906906
return 0;
907907
}
908908

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)
910910
{
911911
struct show_info *show_info = cb_data;
912912
struct push_info *push_info = push_item->util;
@@ -935,7 +935,7 @@ static int cmp_string_with_push(const void *va, const void *vb)
935935
return cmp ? cmp : strcmp(a_push->dest, b_push->dest);
936936
}
937937

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)
939939
{
940940
struct show_info *show_info = cb_data;
941941
struct push_info *push_info = item->util;
@@ -1197,7 +1197,7 @@ static int get_one_remote_for_update(struct remote *remote, void *priv)
11971197
return 0;
11981198
}
11991199

1200-
struct remote_group {
1200+
static struct remote_group {
12011201
const char *name;
12021202
struct string_list *list;
12031203
} remote_group;

builtin-unpack-objects.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ struct obj_info {
158158
#define FLAG_WRITTEN (1u<<21)
159159

160160
static struct obj_info *obj_list;
161-
unsigned nr_objects;
161+
static unsigned nr_objects;
162162

163163
/*
164164
* 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)
200200

201201
if (fsck_object(obj, 1, fsck_error_function))
202202
die("Error in object");
203-
if (!fsck_walk(obj, check_object, 0))
203+
if (!fsck_walk(obj, check_object, NULL))
204204
die("Error on reachable objects of %s", sha1_to_hex(obj->sha1));
205205
write_cached_object(obj);
206206
return 1;
@@ -210,7 +210,7 @@ static void write_rest(void)
210210
{
211211
unsigned i;
212212
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);
214214
}
215215

216216
static void added_object(unsigned nr, enum object_type type,

0 commit comments

Comments
 (0)