Skip to content

Commit

Permalink
misc: do not use plain 0 as NULL [smatch scan]
Browse files Browse the repository at this point in the history
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
  • Loading branch information
kerolasa authored and karelzak committed Feb 20, 2017
1 parent e948f4b commit 8791804
Show file tree
Hide file tree
Showing 73 changed files with 655 additions and 655 deletions.
18 changes: 9 additions & 9 deletions Documentation/boilerplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ int main(int argc, char **argv)
OPT_OPTIONAL /* see howto-man-page.txt about short option */
};
static const struct option longopts[] = {
{"no-argument", no_argument, NULL, 'n'},
{"required", required_argument, NULL, 'r'},
{"xyzzy", no_argument, NULL, OPT_XYZZY},
{"extremely-long-long-option", no_argument, NULL, 'e'},
{"long-explanation", no_argument, NULL, 'l'},
{"foobar", no_argument, NULL, 'f'},
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
{ "no-argument", no_argument, NULL, 'n' },
{ "required", required_argument, NULL, 'r' },
{ "extremely-long-long-option", no_argument, NULL, 'e' },
{ "xyzzy", no_argument, NULL, OPT_XYZZY },
{ "long-explanation", no_argument, NULL, 'l' },
{ "foobar", no_argument, NULL, 'f' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 }
};

setlocale(LC_ALL, "");
Expand Down
6 changes: 3 additions & 3 deletions disk-utils/addpart.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ int main(int argc, char **argv)
int c, fd;

static const struct option longopts[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{NULL, no_argument, 0, '0'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0},
};

setlocale(LC_ALL, "");
Expand Down
2 changes: 1 addition & 1 deletion disk-utils/cfdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2573,7 +2573,7 @@ int main(int argc, char *argv[])
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ "zero", no_argument, NULL, 'z' },
{ NULL, 0, 0, 0 },
{ NULL, 0, NULL, 0 },
};

setlocale(LC_ALL, "");
Expand Down
6 changes: 3 additions & 3 deletions disk-utils/delpart.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ int main(int argc, char **argv)
int c, fd;

static const struct option longopts[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{NULL, no_argument, 0, '0'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0},
};

setlocale(LC_ALL, "");
Expand Down
24 changes: 12 additions & 12 deletions disk-utils/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ static int execute(const char *progname, const char *progpath,
}

argv[argc++] = xstrdup(fs_get_device(fs));
argv[argc] = 0;
argv[argc] = NULL;

if (verbose || noexecute) {
const char *tgt = mnt_fs_get_target(fs);
Expand Down Expand Up @@ -742,7 +742,7 @@ static struct fsck_instance *wait_one(int flags)

if (noexecute) {
inst = instance_list;
prev = 0;
prev = NULL;
#ifdef RANDOM_DEBUG
while (inst->next && (random() & 1)) {
prev = inst;
Expand Down Expand Up @@ -777,7 +777,7 @@ static struct fsck_instance *wait_one(int flags)
warn(_("waitpid failed"));
continue;
}
for (prev = 0, inst = instance_list;
for (prev = NULL, inst = instance_list;
inst;
prev = inst, inst = inst->next) {
if (inst->pid == pid)
Expand Down Expand Up @@ -823,7 +823,7 @@ static struct fsck_instance *wait_one(int flags)
* bit before sending the kill, to give it
* time to set up the signal handler
*/
if (inst2->start_time.tv_sec < time(0) + 2) {
if (inst2->start_time.tv_sec < time(NULL) + 2) {
if (fork() == 0) {
sleep(1);
kill(inst2->pid, SIGUSR1);
Expand Down Expand Up @@ -1029,7 +1029,7 @@ static int fs_match(struct libmnt_fs *fs, struct fs_type_compile *cmp)
int n, ret = 0, checked_type = 0;
char *cp;

if (cmp->list == 0 || cmp->list[0] == 0)
if (cmp->list == NULL || cmp->list[0] == NULL)
return 1;

for (n=0; (cp = cmp->list[n]); n++) {
Expand Down Expand Up @@ -1175,7 +1175,7 @@ static int count_slaves(dev_t disk)
if (!(dir = opendir(dirname)))
return -1;

while ((dp = readdir(dir)) != 0) {
while ((dp = readdir(dir)) != NULL) {
#ifdef _DIRENT_HAVE_D_TYPE
if (dp->d_type != DT_UNKNOWN && dp->d_type != DT_LNK)
continue;
Expand Down Expand Up @@ -1217,7 +1217,7 @@ static int disk_already_active(struct libmnt_fs *fs)
* Don't check a stacked device with any other disk too.
*/
if (!disk || fs_is_stacked(fs))
return (instance_list != 0);
return (instance_list != NULL);

for (inst = instance_list; inst; inst = inst->next) {
dev_t idisk = fs_get_disk(inst->fs, 0);
Expand Down Expand Up @@ -1410,7 +1410,7 @@ static void signal_cancel(int sig __attribute__((__unused__)))
static void parse_argv(int argc, char *argv[])
{
int i, j;
char *arg, *dev, *tmp = 0;
char *arg, *dev, *tmp = NULL;
char options[128];
int opt = 0;
int opts_for_fsck = 0;
Expand All @@ -1422,12 +1422,12 @@ static void parse_argv(int argc, char *argv[])
*/
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = signal_cancel;
sigaction(SIGINT, &sa, 0);
sigaction(SIGTERM, &sa, 0);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);

num_devices = 0;
num_args = 0;
instance_list = 0;
instance_list = NULL;

for (i=1; i < argc; i++) {
arg = argv[i];
Expand Down Expand Up @@ -1534,7 +1534,7 @@ static void parse_argv(int argc, char *argv[])
serialize = 1;
break;
case 't':
tmp = 0;
tmp = NULL;
if (fstype)
usage(stderr);
if (arg[j+1])
Expand Down
18 changes: 9 additions & 9 deletions disk-utils/fsck.cramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static void test_crc(int start)
return;
}

crc = crc32(0L, Z_NULL, 0);
crc = crc32(0L, NULL, 0);

buf =
mmap(NULL, super.size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
Expand All @@ -237,7 +237,7 @@ static void test_crc(int start)
}
if (buf != MAP_FAILED) {
((struct cramfs_super *)((unsigned char *) buf + start))->fsid.crc =
crc32(0L, Z_NULL, 0);
crc32(0L, NULL, 0);
crc = crc32(crc, (unsigned char *) buf + start, super.size - start);
munmap(buf, super.size);
} else {
Expand All @@ -255,7 +255,7 @@ static void test_crc(int start)
break;
if (length == 0)
((struct cramfs_super *)buf)->fsid.crc =
crc32(0L, Z_NULL, 0);
crc32(0L, NULL, 0);
length += retval;
if (length > (super.size - start)) {
crc = crc32(crc, buf,
Expand Down Expand Up @@ -646,12 +646,12 @@ int main(int argc, char **argv)
size_t length = 0;

static const struct option longopts[] = {
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
{"blocksize", required_argument, 0, 'b'},
{"extract", optional_argument, 0, 'x'},
{NULL, no_argument, 0, '0'},
{"verbose", no_argument, NULL, 'v'},
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
{"blocksize", required_argument, NULL, 'b'},
{"extract", optional_argument, NULL, 'x'},
{NULL, 0, NULL, 0},
};

setlocale(LC_MESSAGES, "");
Expand Down
10 changes: 5 additions & 5 deletions disk-utils/isosize.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ int main(int argc, char **argv)
long divisor = 0;

static const struct option longopts[] = {
{"divisor", required_argument, 0, 'd'},
{"sectors", no_argument, 0, 'x'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
{NULL, 0, 0, 0}
{"divisor", required_argument, NULL, 'd'},
{"sectors", no_argument, NULL, 'x'},
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};

setlocale(LC_ALL, "");
Expand Down
6 changes: 3 additions & 3 deletions disk-utils/mkfs.cramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ static unsigned int parse_directory(struct entry *root_entry, const char *name,
endpath++;

/* read in the directory and sort */
dircount = scandir(name, &dirlist, 0, cramsort);
dircount = scandir(name, &dirlist, NULL, cramsort);

if (dircount < 0)
err(MKFS_EX_ERROR, _("could not read directory %s"), name);
Expand Down Expand Up @@ -412,7 +412,7 @@ static unsigned int write_superblock(struct entry *root, char *base, int size)
super->size = size;
memcpy(super->signature, CRAMFS_SIGNATURE, sizeof(super->signature));

super->fsid.crc = crc32(0L, Z_NULL, 0);
super->fsid.crc = crc32(0L, NULL, 0);
super->fsid.edition = opt_edition;
super->fsid.blocks = total_blocks;
super->fsid.files = total_nodes;
Expand Down Expand Up @@ -706,7 +706,7 @@ int main(int argc, char **argv)
loff_t fslen_ub = sizeof(struct cramfs_super);
unsigned int fslen_max;
char const *dirname, *outfile;
uint32_t crc = crc32(0L, Z_NULL, 0);
uint32_t crc = crc32(0L, NULL, 0);
int c;
cramfs_is_big_endian = HOST_IS_BIG_ENDIAN; /* default is to use host order */

Expand Down
18 changes: 9 additions & 9 deletions disk-utils/mkswap.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,15 @@ int main(int argc, char **argv)
uuid_t uuid_dat;
#endif
static const struct option longopts[] = {
{ "check", no_argument, 0, 'c' },
{ "force", no_argument, 0, 'f' },
{ "pagesize", required_argument, 0, 'p' },
{ "label", required_argument, 0, 'L' },
{ "swapversion", required_argument, 0, 'v' },
{ "uuid", required_argument, 0, 'U' },
{ "version", no_argument, 0, 'V' },
{ "help", no_argument, 0, 'h' },
{ NULL, 0, 0, 0 }
{ "check", no_argument, NULL, 'c' },
{ "force", no_argument, NULL, 'f' },
{ "pagesize", required_argument, NULL, 'p' },
{ "label", required_argument, NULL, 'L' },
{ "swapversion", required_argument, NULL, 'v' },
{ "uuid", required_argument, NULL, 'U' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 }
};

setlocale(LC_ALL, "");
Expand Down
10 changes: 5 additions & 5 deletions disk-utils/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ int main(int argc, char *argv[])
struct stat statbuf;

static const struct option longopts[] = {
{"query", no_argument, 0, 'q'},
{"all", no_argument, 0, 'a'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
{NULL, no_argument, 0, '0'},
{"query", no_argument, NULL, 'q'},
{"all", no_argument, NULL, 'a'},
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, '0'},
};

setlocale(LC_ALL, "");
Expand Down
6 changes: 3 additions & 3 deletions disk-utils/resizepart.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ int main(int argc, char **argv)
uint64_t start;

static const struct option longopts[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{NULL, no_argument, 0, '0'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, '0'},
};

setlocale(LC_ALL, "");
Expand Down
2 changes: 1 addition & 1 deletion disk-utils/sfdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,7 @@ int main(int argc, char *argv[])
{ "id", no_argument, NULL, 'c' }, /* deprecated */
{ "print-id",no_argument, NULL, OPT_PRINT_ID }, /* deprecated */

{ NULL, 0, 0, 0 },
{ NULL, 0, NULL, 0 },
};

setlocale(LC_ALL, "");
Expand Down
10 changes: 5 additions & 5 deletions disk-utils/swaplabel.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ int main(int argc, char *argv[])
int c, rc = -1;

static const struct option longopts[] = {
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'V' },
{ "label", 1, 0, 'L' },
{ "uuid", 1, 0, 'U' },
{ NULL, 0, 0, 0 }
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ "label", required_argument, NULL, 'L' },
{ "uuid", required_argument, NULL, 'U' },
{ NULL, 0, NULL, 0 }
};

setlocale(LC_ALL, "");
Expand Down
2 changes: 1 addition & 1 deletion include/pt-mbr-partnames.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@
{0xfe, N_("LANstep")}, /* SpeedStor >1024 cyl. or LANstep */
{0xff, N_("BBT")}, /* Xenix Bad Block Table */

{ 0, 0 }
{ 0, NULL }
4 changes: 2 additions & 2 deletions lib/randutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static void crank_random(void)
int i;
struct timeval tv;

gettimeofday(&tv, 0);
gettimeofday(&tv, NULL);
srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);

#ifdef DO_JRAND_MIX
Expand All @@ -68,7 +68,7 @@ static void crank_random(void)
ul_jrand_seed[2] = (tv.tv_sec ^ tv.tv_usec) >> 16;
#endif
/* Crank the random number generator a few times */
gettimeofday(&tv, 0);
gettimeofday(&tv, NULL);
for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--)
rand();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int setup_timer(timer_t * t_id, struct itimerval *timeout,
sig_a.sa_flags = SA_SIGINFO;
sig_a.sa_sigaction = timeout_handler;

if (sigaction(SIGALRM, &sig_a, 0))
if (sigaction(SIGALRM, &sig_a, NULL))
return 1;
if (timer_create(CLOCK_MONOTONIC, &sig_e, t_id))
return 1;
Expand Down
6 changes: 3 additions & 3 deletions libblkid/src/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache)
iter->magic = DEV_ITERATE_MAGIC;
iter->cache = cache;
iter->p = cache->bic_devs.next;
iter->search_type = 0;
iter->search_value = 0;
iter->search_type = NULL;
iter->search_value = NULL;
}
return iter;
}
Expand Down Expand Up @@ -181,7 +181,7 @@ int blkid_dev_next(blkid_dev_iterate iter,

if (!ret_dev || !iter || iter->magic != DEV_ITERATE_MAGIC)
return -1;
*ret_dev = 0;
*ret_dev = NULL;
while (iter->p != &iter->cache->bic_devs) {
dev = list_entry(iter->p, struct blkid_struct_dev, bid_devs);
iter->p = iter->p->next;
Expand Down
Loading

0 comments on commit 8791804

Please sign in to comment.