toolbox: turn on -Werror

- Deal with some signedness issues
- Deal with some size issues
- Deal with NULL pointer issues
- Deal with some -Wunused issues

Change-Id: I1479dd90d690084491bae3475f2c547833519a57
This commit is contained in:
Mark Salyzyn 2014-05-08 09:31:43 -07:00
parent 3fe8afa404
commit aa907768af
27 changed files with 58 additions and 84 deletions

View file

@ -96,7 +96,7 @@ LOCAL_C_INCLUDES := bionic/libc/bionic
LOCAL_CFLAGS += \
-std=gnu99 \
-Wno-unused-parameter \
-Werror -Wno-unused-parameter \
-include bsd-compatibility.h \
LOCAL_SHARED_LIBRARIES := \

View file

@ -95,12 +95,14 @@ enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
static int copy(char *[], enum op, int);
#ifndef ANDROID
static void
progress(int sig __unused)
{
pinfo++;
}
#endif
int
cp_main(int argc, char *argv[])

View file

@ -380,10 +380,11 @@ copy_special(struct stat *from_stat, int exists)
int
setfile(struct stat *fs, int fd)
{
int rval, islink;
int rval = 0;
#ifndef ANDROID
int islink = S_ISLNK(fs->st_mode);
#endif
rval = 0;
islink = S_ISLNK(fs->st_mode);
fs->st_mode &= S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO;
/*
@ -401,13 +402,13 @@ setfile(struct stat *fs, int fd)
fs->st_mode &= ~(S_ISUID | S_ISGID);
}
#ifdef ANDROID
if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode)) {
if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode)) {
#else
if (fd ? fchmod(fd, fs->st_mode) : lchmod(to.p_path, fs->st_mode)) {
if (fd ? fchmod(fd, fs->st_mode) : lchmod(to.p_path, fs->st_mode)) {
#endif
warn("chmod: %s", to.p_path);
rval = 1;
}
warn("chmod: %s", to.p_path);
rval = 1;
}
#ifndef ANDROID
if (!islink && !Nflag) {

View file

@ -140,14 +140,12 @@ static char *parse_time(const char *str, struct timeval *ts) {
int date_main(int argc, char *argv[])
{
int c;
int c;
int res;
struct tm tm;
time_t t;
struct timeval tv;
struct timespec ts;
char strbuf[260];
int fd;
struct tm tm;
time_t t;
struct timeval tv;
char strbuf[260];
int useutc = 0;
@ -177,7 +175,6 @@ int date_main(int argc, char *argv[])
int hasfmt = argc == optind + 1 && argv[optind][0] == '+';
if(optind == argc || hasfmt) {
char buf[2000];
time(&t);
if (useutc) {
gmtime_r(&t, &tm);

View file

@ -356,7 +356,7 @@ dd_in(void)
++st.in_full;
/* Handle full input blocks. */
} else if (n == in.dbsz) {
} else if (n == (int64_t)in.dbsz) {
in.dbcnt += in.dbrcnt = n;
++st.in_full;
@ -521,7 +521,7 @@ dd_out(int force)
outp += nw;
st.bytes += nw;
if (nw == n) {
if (n != out.dbsz)
if (n != (int64_t)out.dbsz)
++st.out_part;
else
++st.out_full;
@ -649,8 +649,8 @@ pos_in(void)
void
pos_out(void)
{
// struct mtop t_op;
int cnt, n;
/* struct mtop t_op; */
int64_t cnt, n;
/*
* If not a tape, try seeking on the file. Seeking on a pipe is
@ -681,7 +681,7 @@ pos_out(void)
}
/* Read it. */
for (cnt = 0; cnt < out.offset; ++cnt) {
for (cnt = 0; cnt < (int64_t)out.offset; ++cnt) {
if ((n = read(out.fd, out.db, out.dbsz)) > 0)
continue;
@ -705,8 +705,8 @@ pos_out(void)
/* NOTREACHED */
}
while (cnt++ < out.offset)
if ((n = bwrite(out.fd, out.db, out.dbsz)) != out.dbsz) {
while (cnt++ < (int64_t)out.offset)
if ((n = bwrite(out.fd, out.db, out.dbsz)) != (int64_t)out.dbsz) {
fprintf(stderr, "%s: cannot position "
"by writing: %s\n",
out.name, strerror(errno));
@ -1153,7 +1153,7 @@ c_arg(const void *a, const void *b)
((const struct arg *)b)->name));
}
static long long strsuftoll(const char* name, const char* arg, int def, unsigned int max)
static long long strsuftoll(const char* name, const char* arg, int def, unsigned long long max)
{
long long result;
@ -1180,7 +1180,7 @@ static void
f_count(char *arg)
{
cpy_cnt = strsuftoll("block count", arg, 0, LLONG_MAX);
cpy_cnt = (uint64_t)strsuftoll("block count", arg, 0, 0xFFFFFFFFFFFFFFFFULL);
if (!cpy_cnt)
terminate(0);
}
@ -1228,14 +1228,14 @@ static void
f_seek(char *arg)
{
out.offset = strsuftoll("seek blocks", arg, 0, LLONG_MAX);
out.offset = (uint64_t)strsuftoll("seek blocks", arg, 0, 0xFFFFFFFFFFFFFFFFULL);
}
static void
f_skip(char *arg)
{
in.offset = strsuftoll("skip blocks", arg, 0, LLONG_MAX);
in.offset = (uint64_t)strsuftoll("skip blocks", arg, 0, 0xFFFFFFFFFFFFFFFFULL);
}
static void

View file

@ -76,7 +76,7 @@ du_main(int argc, char *argv[])
int64_t totalblocks;
int ftsoptions, listfiles;
int depth;
int Hflag, Lflag, aflag, ch, cflag, dflag, gkmflag, nflag, rval, sflag;
int Hflag, Lflag, aflag, ch, cflag, dflag, gkmflag, rval, sflag;
const char *noargv[2];
Hflag = Lflag = aflag = cflag = dflag = gkmflag = sflag = 0;

View file

@ -492,13 +492,11 @@ int getevent_main(int argc, char *argv[])
int c;
int i;
int res;
int pollres;
int get_time = 0;
int print_device = 0;
char *newline = "\n";
uint16_t get_switch = 0;
struct input_event event;
int version;
int print_flags = 0;
int print_flags_set = 0;
int dont_block = -1;
@ -629,7 +627,8 @@ int getevent_main(int argc, char *argv[])
return 0;
while(1) {
pollres = poll(ufds, nfds, -1);
//int pollres =
poll(ufds, nfds, -1);
//printf("poll %d, returned %d\n", nfds, pollres);
if(ufds[0].revents & POLLIN) {
read_notify(device_path, ufds[0].fd, print_flags);

View file

@ -652,6 +652,7 @@ static struct label snd_labels[] = {
LABEL_END,
};
#if 0
static struct label id_labels[] = {
LABEL(ID_BUS),
LABEL(ID_VENDOR),
@ -682,6 +683,7 @@ static struct label bus_labels[] = {
LABEL(BUS_SPI),
LABEL_END,
};
#endif
static struct label mt_tool_labels[] = {
LABEL(MT_TOOL_FINGER),

View file

@ -35,8 +35,6 @@ int __system_property_wait(prop_info *pi);
int getprop_main(int argc, char *argv[])
{
int n = 0;
if (argc == 1) {
list_properties();
} else {

View file

@ -78,7 +78,9 @@ static inline int
grep_refill(struct file *f)
{
ssize_t nr;
#ifndef ANDROID
int bzerr;
#endif
bufpos = buffer;
bufrem = 0;

View file

@ -403,7 +403,7 @@ grep_main(int argc, char *argv[])
Aflag = 0;
else if (Aflag > LLONG_MAX / 10) {
errno = ERANGE;
err(2, NULL);
err(2, "%llu", Aflag);
}
Aflag = Bflag = (Aflag * 10) + (c - '0');
break;
@ -420,10 +420,10 @@ grep_main(int argc, char *argv[])
l = strtoull(optarg, &ep, 10);
if (((errno == ERANGE) && (l == ULLONG_MAX)) ||
((errno == EINVAL) && (l == 0)))
err(2, NULL);
err(2, "strtoull");
else if (ep[0] != '\0') {
errno = EINVAL;
err(2, NULL);
err(2, "empty");
}
if (c == 'A')
Aflag = l;
@ -509,10 +509,10 @@ grep_main(int argc, char *argv[])
mcount = strtoull(optarg, &ep, 10);
if (((errno == ERANGE) && (mcount == ULLONG_MAX)) ||
((errno == EINVAL) && (mcount == 0)))
err(2, NULL);
err(2, "strtoull");
else if (ep[0] != '\0') {
errno = EINVAL;
err(2, NULL);
err(2, "empty");
}
break;
case 'n':

View file

@ -14,7 +14,6 @@ int hd_main(int argc, char *argv[])
unsigned char buf[4096];
int res;
int read_len;
int rv = 0;
int i;
int filepos = 0;
int sum;

View file

@ -21,9 +21,9 @@ int ioctl_main(int argc, char *argv[])
int arg_size = 4;
int direct_arg = 0;
uint32_t ioctl_nr;
void *ioctl_args;
void *ioctl_args = NULL;
uint8_t *ioctl_argp;
uint8_t *ioctl_argp_save;
uint8_t *ioctl_argp_save = NULL;
int rem;
do {
@ -112,6 +112,7 @@ int ioctl_main(int argc, char *argv[])
else
res = ioctl(fd, ioctl_nr, 0);
if (res < 0) {
free(ioctl_args);
fprintf(stderr, "ioctl 0x%x failed, %d\n", ioctl_nr, res);
return 1;
}
@ -124,5 +125,6 @@ int ioctl_main(int argc, char *argv[])
}
printf("\n");
}
free(ioctl_args);
return 0;
}

View file

@ -10,7 +10,7 @@
int load_policy_main(int argc, char **argv)
{
int fd, rc, vers;
int fd, rc;
struct stat sb;
void *map;
const char *path;

View file

@ -443,7 +443,6 @@ static int listpath(const char *name, int flags)
int ls_main(int argc, char **argv)
{
int flags = 0;
int listed = 0;
if(argc > 1) {
int i;

View file

@ -99,10 +99,7 @@ out:
static void print_maps(struct pid_info_t* info)
{
FILE *maps;
char buffer[PATH_MAX + 100];
size_t offset;
int major, minor;
char device[10];
long int inode;
char file[PATH_MAX];

View file

@ -15,7 +15,6 @@ static int usage()
int mkdir_main(int argc, char *argv[])
{
int symbolic = 0;
int ret;
if(argc < 2 || strcmp(argv[1], "--help") == 0) {
return usage();

View file

@ -360,7 +360,7 @@ newfs_msdos_main(int argc, char *argv[])
if (!opt_create && !strchr(fname, '/')) {
snprintf(buf, sizeof(buf), "%s%s", _PATH_DEV, fname);
if (!(fname = strdup(buf)))
err(1, NULL);
err(1, "%s", buf);
}
dtype = *argv;
if (opt_create) {
@ -493,7 +493,7 @@ newfs_msdos_main(int argc, char *argv[])
if (!strchr(bname, '/')) {
snprintf(buf, sizeof(buf), "/boot/%s", bname);
if (!(bname = strdup(buf)))
err(1, NULL);
err(1, "%s", buf);
}
if ((fd1 = open(bname, O_RDONLY)) == -1 || fstat(fd1, &sb))
err(1, "%s", bname);
@ -611,7 +611,7 @@ newfs_msdos_main(int argc, char *argv[])
now = tv.tv_sec;
tm = localtime(&now);
if (!(img = malloc(bpb.bps)))
err(1, NULL);
err(1, "%u", bpb.bps);
dir = bpb.res + (bpb.spf ? bpb.spf : bpb.bspf) * bpb.nft;
for (lsn = 0; lsn < dir + (fat == 32 ? bpb.spc : rds); lsn++) {
x = lsn;
@ -728,14 +728,14 @@ newfs_msdos_main(int argc, char *argv[])
static void
check_mounted(const char *fname, mode_t mode)
{
#ifdef ANDROID
warnx("Skipping mount checks");
#else
struct statfs *mp;
const char *s1, *s2;
size_t len;
int n, r;
#ifdef ANDROID
warnx("Skipping mount checks");
#else
if (!(n = getmntinfo(&mp, MNT_NOWAIT)))
err(1, "getmntinfo");
len = strlen(_PATH_DEV);

View file

@ -40,7 +40,7 @@ static int ps_line(int pid, int tid, char *namefilter)
struct stat stats;
int fd, r;
char *ptr, *name, *state;
int ppid, tty;
int ppid;
unsigned wchan, rss, vss, eip;
unsigned utime, stime;
int prio, nice, rtprio, sched, psr;
@ -88,7 +88,7 @@ static int ps_line(int pid, int tid, char *namefilter)
ppid = atoi(nexttok(&ptr));
nexttok(&ptr); // pgrp
nexttok(&ptr); // sid
tty = atoi(nexttok(&ptr));
nexttok(&ptr); // tty
nexttok(&ptr); // tpgid
nexttok(&ptr); // flags
@ -130,7 +130,7 @@ static int ps_line(int pid, int tid, char *namefilter)
rtprio = atoi(nexttok(&ptr)); // rt_priority
sched = atoi(nexttok(&ptr)); // scheduling policy
tty = atoi(nexttok(&ptr));
nexttok(&ptr); // tty
if(tid != 0) {
ppid = pid;

View file

@ -11,7 +11,6 @@ static int usage()
int rmdir_main(int argc, char *argv[])
{
int symbolic = 0;
int ret;
if(argc < 2) return usage();

View file

@ -227,7 +227,6 @@ static void update_table(DIR *d, uint32_t flags)
}
for (i = 0; i < last_processes.active; i++) {
int pid = last_processes.data[i].pid;
int tid = last_processes.data[i].tid;
for (j = 0; j < processes.active; j++)
if (pid == processes.data[j].pid)
break;
@ -270,9 +269,6 @@ int schedtop_main(int argc, char **argv)
{
int c;
DIR *d;
struct dirent *de;
char *namefilter = 0;
int pidfilter = 0;
uint32_t flags = 0;
int delay = 3000000;
float delay_f;

View file

@ -47,9 +47,8 @@ struct input_event {
int sendevent_main(int argc, char *argv[])
{
int i;
int fd;
int ret;
ssize_t ret;
int version;
struct input_event event;
@ -72,7 +71,7 @@ int sendevent_main(int argc, char *argv[])
event.code = atoi(argv[3]);
event.value = atoi(argv[4]);
ret = write(fd, &event, sizeof(event));
if(ret < sizeof(event)) {
if(ret < (ssize_t) sizeof(event)) {
fprintf(stderr, "write event failed, %s\n", strerror(errno));
return -1;
}

View file

@ -7,8 +7,6 @@
int start_main(int argc, char *argv[])
{
char buf[1024];
if(argc > 1) {
property_set("ctl.start", argv[1]);
} else {

View file

@ -5,8 +5,6 @@
int stop_main(int argc, char *argv[])
{
char buf[1024];
if(argc > 1) {
property_set("ctl.stop", argv[1]);
} else{

View file

@ -328,7 +328,6 @@ static void read_procs(void) {
static int read_stat(char *filename, struct proc_info *proc) {
FILE *file;
char buf[MAX_LINE], *open_paren, *close_paren;
int res, idx;
file = fopen(filename, "r");
if (!file) return 1;
@ -414,9 +413,7 @@ static void print_procs(void) {
struct proc_info *old_proc, *proc;
long unsigned total_delta_time;
struct passwd *user;
struct group *group;
char *user_str, user_buf[20];
char *group_str, group_buf[20];
for (i = 0; i < num_new_procs; i++) {
if (new_procs[i]) {
@ -467,19 +464,12 @@ static void print_procs(void) {
if (!proc || (max_procs && (i >= max_procs)))
break;
user = getpwuid(proc->uid);
group = getgrgid(proc->gid);
if (user && user->pw_name) {
user_str = user->pw_name;
} else {
snprintf(user_buf, 20, "%d", proc->uid);
user_str = user_buf;
}
if (group && group->gr_name) {
group_str = group->gr_name;
} else {
snprintf(group_buf, 20, "%d", proc->gid);
group_str = group_buf;
}
if (!threads)
printf("%5d %2d %3ld%% %c %5d %6ldK %6ldK %3s %-8.8s %s\n", proc->pid, proc->prs, proc->delta_time * 100 / total_delta_time, proc->state, proc->num_threads,
proc->vss / 1024, proc->rss * getpagesize() / 1024, proc->policy, user_str, proc->name[0] != 0 ? proc->name : proc->tname);

View file

@ -33,7 +33,6 @@ static int is_loop_mount(const char* path, char *loopdev)
char mount_path[256];
char rest[256];
int result = 0;
int path_length = strlen(path);
f = fopen("/proc/mounts", "r");
if (!f) {

View file

@ -77,9 +77,7 @@ static void update_watchlist(const prop_info *pi, void *cookie)
int watchprops_main(int argc, char *argv[])
{
unsigned serial = 0;
unsigned count = 0;
unsigned n;
unsigned serial;
Hashmap *watchlist = hashmapCreate(1024, str_hash, str_equals);
if (!watchlist)
@ -87,7 +85,7 @@ int watchprops_main(int argc, char *argv[])
__system_property_foreach(populate_watchlist, watchlist);
for(;;) {
for(serial = 0;;) {
serial = __system_property_wait_any(serial);
__system_property_foreach(update_watchlist, watchlist);
}