Skip to content

Commit e99d59f

Browse files
author
Linus Torvalds
committed
sparse cleanup
Fix various things that sparse complains about: - use NULL instead of 0 - make sure we declare everything properly, or mark it static - use proper function declarations ("fn(void)" instead of "fn()") Sparse is always right.
1 parent 7ca4525 commit e99d59f

18 files changed

+33
-31
lines changed

date.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <ctype.h>
1111
#include <time.h>
1212

13+
#include "cache.h"
14+
1315
static time_t my_mktime(struct tm *tm)
1416
{
1517
static const int mdays[] = {

diff-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ int main(int argc, char **argv)
204204

205205
diff_setup(detect_rename, diff_score_opt, reverse_diff,
206206
(generate_patch ? -1 : line_termination),
207-
0, 0);
207+
NULL, 0);
208208

209209
mark_merge_entries();
210210

211-
tree = read_object_with_reference(tree_sha1, "tree", &size, 0);
211+
tree = read_object_with_reference(tree_sha1, "tree", &size, NULL);
212212
if (!tree)
213213
die("bad tree object %s", argv[1]);
214214
if (read_tree(tree, size, 1))

diff-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int main(int argc, char **argv)
8686

8787
diff_setup(detect_rename, diff_score_opt, reverse_diff,
8888
(generate_patch ? -1 : line_termination),
89-
0, 0);
89+
NULL, 0);
9090

9191
for (i = 0; i < entries; i++) {
9292
struct stat st;

diff-helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static int parse_diff_raw_output(const char *buf)
7979
if ((*cp != '\t') && *cp != ' ')
8080
return -1;
8181
strcpy(path, ++cp);
82-
diff_change(old_mode, new_mode, old_sha1, new_sha1, path, 0);
82+
diff_change(old_mode, new_mode, old_sha1, new_sha1, path, NULL);
8383
break;
8484
default:
8585
return -1;

diff-tree.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ static int diff_tree_sha1(const unsigned char *old, const unsigned char *new, co
254254
unsigned long size1, size2;
255255
int retval;
256256

257-
tree1 = read_object_with_reference(old, "tree", &size1, 0);
257+
tree1 = read_object_with_reference(old, "tree", &size1, NULL);
258258
if (!tree1)
259259
die("unable to read source tree (%s)", sha1_to_hex(old));
260-
tree2 = read_object_with_reference(new, "tree", &size2, 0);
260+
tree2 = read_object_with_reference(new, "tree", &size2, NULL);
261261
if (!tree2)
262262
die("unable to read destination tree (%s)", sha1_to_hex(new));
263263
retval = diff_tree(tree1, size1, tree2, size2, base);
@@ -273,7 +273,7 @@ static int diff_tree_sha1_top(const unsigned char *old,
273273

274274
diff_setup(detect_rename, diff_score_opt, reverse_diff,
275275
(generate_patch ? -1 : line_termination),
276-
0, 0);
276+
NULL, 0);
277277
ret = diff_tree_sha1(old, new, base);
278278
diff_flush();
279279
return ret;
@@ -287,8 +287,8 @@ static int diff_root_tree(const unsigned char *new, const char *base)
287287

288288
diff_setup(detect_rename, diff_score_opt, reverse_diff,
289289
(generate_patch ? -1 : line_termination),
290-
0, 0);
291-
tree = read_object_with_reference(new, "tree", &size, 0);
290+
NULL, 0);
291+
tree = read_object_with_reference(new, "tree", &size, NULL);
292292
if (!tree)
293293
die("unable to read root tree (%s)", sha1_to_hex(new));
294294
retval = diff_tree("", 0, tree, size, base);

diff.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static void run_external_diff(const char *name,
385385
*arg++ = temp[1].mode;
386386
if (other)
387387
*arg++ = other;
388-
*arg = 0;
388+
*arg = NULL;
389389
execvp(pgm, (char *const*) exec_arg);
390390
}
391391
else
@@ -504,7 +504,7 @@ static void free_data(struct diff_spec_hold *s)
504504
else if (s->flags & SHOULD_MUNMAP)
505505
munmap(s->data, s->size);
506506
s->flags &= ~(SHOULD_FREE|SHOULD_MUNMAP);
507-
s->data = 0;
507+
s->data = NULL;
508508
}
509509

510510
static void flush_remaining_diff(struct diff_spec_hold *elem,
@@ -541,7 +541,7 @@ static int is_exact_match(struct diff_spec_hold *src,
541541
return 0;
542542
}
543543

544-
int estimate_similarity(struct diff_spec_hold *src, struct diff_spec_hold *dst)
544+
static int estimate_similarity(struct diff_spec_hold *src, struct diff_spec_hold *dst)
545545
{
546546
/* src points at a deleted file and dst points at a created
547547
* file. They may be quite similar, in which case we want to

export.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/*
55
* Show one commit
66
*/
7-
void show_commit(struct commit *commit)
7+
static void show_commit(struct commit *commit)
88
{
99
char cmdline[400];
1010
char hex[100];
@@ -27,7 +27,7 @@ void show_commit(struct commit *commit)
2727
/*
2828
* Show all unseen commits, depth-first
2929
*/
30-
void show_unseen(struct commit *top)
30+
static void show_unseen(struct commit *top)
3131
{
3232
struct commit_list *parents;
3333

@@ -42,15 +42,15 @@ void show_unseen(struct commit *top)
4242
show_commit(top);
4343
}
4444

45-
void export(struct commit *top, struct commit *base)
45+
static void export(struct commit *top, struct commit *base)
4646
{
4747
mark_reachable(&top->object, 1);
4848
if (base)
4949
mark_reachable(&base->object, 2);
5050
show_unseen(top);
5151
}
5252

53-
struct commit *get_commit(unsigned char *sha1)
53+
static struct commit *get_commit(unsigned char *sha1)
5454
{
5555
struct commit *commit = lookup_commit(sha1);
5656
if (!commit->object.parsed) {

init-db.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
#include "cache.h"
77

8-
void safe_create_dir(const char *dir)
8+
static void safe_create_dir(const char *dir)
99
{
1010
if (mkdir(dir, 0755) < 0) {
1111
if (errno != EEXIST) {

ls-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static int cmp_name(const void *p1, const void *p2)
179179
e2->name, e2->len);
180180
}
181181

182-
static void show_killed_files()
182+
static void show_killed_files(void)
183183
{
184184
int i;
185185
for (i = 0; i < nr_dir; i++) {

ls-tree.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
#include "cache.h"
77

8-
int line_termination = '\n';
9-
int recursive = 0;
8+
static int line_termination = '\n';
9+
static int recursive = 0;
1010

1111
struct path_prefix {
1212
struct path_prefix *prev;
@@ -73,7 +73,7 @@ static int list(unsigned char *sha1)
7373
void *buffer;
7474
unsigned long size;
7575

76-
buffer = read_object_with_reference(sha1, "tree", &size, 0);
76+
buffer = read_object_with_reference(sha1, "tree", &size, NULL);
7777
if (!buffer)
7878
die("unable to read sha1 file");
7979
list_recursive(buffer, "tree", size, NULL);

0 commit comments

Comments
 (0)