summaryrefslogtreecommitdiffstats
path: root/usr.bin/usbhidaction
diff options
context:
space:
mode:
authordwmalone <dwmalone@FreeBSD.org>2004-03-09 11:35:43 +0000
committerdwmalone <dwmalone@FreeBSD.org>2004-03-09 11:35:43 +0000
commit036b26782d13d8853608666d94a5d6313120fa92 (patch)
treef6bab6e2974724b3f6f952034e9a57376282581b /usr.bin/usbhidaction
parente213a22583d9fff2404e3b6c8b3c5a099b934471 (diff)
downloadFreeBSD-src-036b26782d13d8853608666d94a5d6313120fa92.zip
FreeBSD-src-036b26782d13d8853608666d94a5d6313120fa92.tar.gz
Misc fixes brought to light by WARNS=6:
1) Constness, unusedness and size_tness. 2) Don't clobber the value returned by hid_report_size in the daemon case. 3) Don't misspell "sizeof buf" as 100. 4) Don't run off the end of a buffer if the pid is about a google. 5) Avoid shadowing the usage function.
Diffstat (limited to 'usr.bin/usbhidaction')
-rw-r--r--usr.bin/usbhidaction/usbhidaction.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/usr.bin/usbhidaction/usbhidaction.c b/usr.bin/usbhidaction/usbhidaction.c
index e79011c..e1f67b0 100644
--- a/usr.bin/usbhidaction/usbhidaction.c
+++ b/usr.bin/usbhidaction/usbhidaction.c
@@ -58,7 +58,7 @@
static int verbose = 0;
static int isdemon = 0;
static int reparse = 1;
-static char * pidfile = "/var/run/usbaction.pid";
+static const char * pidfile = "/var/run/usbaction.pid";
struct command {
struct command *next;
@@ -83,7 +83,7 @@ void docmd(struct command *, int, const char *, int, char **);
void freecommands(struct command *);
static void
-sighup(int sig)
+sighup(int sig __unused)
{
reparse = 1;
}
@@ -93,7 +93,8 @@ main(int argc, char **argv)
{
const char *conf = NULL;
const char *dev = NULL;
- int fd, fp, ch, sz, n, val, i;
+ int fd, fp, ch, n, val, i;
+ size_t sz, sz1;
int demon, ignore, dieearly;
report_desc_t repd;
char buf[100];
@@ -158,10 +159,10 @@ main(int argc, char **argv)
commands = parse_conf(conf, repd, reportid, ignore);
- sz = hid_report_size(repd, hid_input, reportid);
+ sz = (size_t)hid_report_size(repd, hid_input, reportid);
if (verbose)
- printf("report size %d\n", sz);
+ printf("report size %zu\n", sz);
if (sz > sizeof buf)
errx(1, "report too large");
@@ -170,8 +171,10 @@ main(int argc, char **argv)
if (demon) {
fp = open(pidfile, O_WRONLY|O_CREAT, S_IRUSR|S_IRGRP|S_IROTH);
if (fp >= 0) {
- sz=snprintf(buf,100, "%d\n", getpid());
- write(fp, buf, sz);
+ sz1 = snprintf(buf, sizeof buf, "%d\n", getpid());
+ if (sz1 > sizeof buf)
+ sz1 = sizeof buf;
+ write(fp, buf, sz1);
close(fp);
} else
err(1, "%s", pidfile);
@@ -264,7 +267,7 @@ parse_conf(const char *conf, report_desc_t repd, int reportid, int ignore)
char *p;
int line;
char buf[SIZE], name[SIZE], value[SIZE], debounce[SIZE], action[SIZE];
- char usage[SIZE], coll[SIZE];
+ char usbuf[SIZE], coll[SIZE];
struct command *cmd, *cmds;
struct hid_data *d;
struct hid_item h;
@@ -364,22 +367,22 @@ parse_conf(const char *conf, report_desc_t repd, int reportid, int ignore)
range = 0;
}
for (u = lo; u <= hi; u++) {
- snprintf(usage, sizeof usage, "%s:%s",
+ snprintf(usbuf, sizeof usbuf, "%s:%s",
hid_usage_page(HID_PAGE(u)),
hid_usage_in_page(u));
if (verbose > 2)
- printf("usage %s\n", usage);
- if (!strcasecmp(usage, name))
+ printf("usage %s\n", usbuf);
+ if (!strcasecmp(usbuf, name))
goto foundhid;
if (coll[0]) {
- snprintf(usage, sizeof usage,
+ snprintf(usbuf, sizeof usbuf,
"%s.%s:%s", coll+1,
hid_usage_page(HID_PAGE(u)),
hid_usage_in_page(u));
if (verbose > 2)
printf("usage %s\n",
- usage);
- if (!strcasecmp(usage, name))
+ usbuf);
+ if (!strcasecmp(usbuf, name))
goto foundhid;
}
}
OpenPOWER on IntegriCloud