aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@member.fsf.org>2015-12-29 16:04:45 +0100
committerMattias Andrée <maandree@member.fsf.org>2015-12-29 16:04:45 +0100
commit98d15bdfc7ae70f89f58d46b1727aed19ceaf387 (patch)
tree762d155dcd0865a0fda43b70fe490be85beee994
parentadd build system + add news file + update deps (diff)
downloadsat-98d15bdfc7ae70f89f58d46b1727aed19ceaf387.tar.gz
sat-98d15bdfc7ae70f89f58d46b1727aed19ceaf387.tar.bz2
sat-98d15bdfc7ae70f89f58d46b1727aed19ceaf387.tar.xz
fix warnings
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
-rw-r--r--src/client.c9
-rw-r--r--src/client.h3
-rw-r--r--src/common.h2
-rw-r--r--src/daemon.c6
-rw-r--r--src/daemonise.c2
-rw-r--r--src/parse_time.c7
-rw-r--r--src/satd-add.c6
-rw-r--r--src/satd-list.c10
-rw-r--r--src/satd.c15
-rw-r--r--src/satq.c2
-rw-r--r--src/satrm.c2
11 files changed, 35 insertions, 29 deletions
diff --git a/src/client.c b/src/client.c
index 6da3b39..026813b 100644
--- a/src/client.c
+++ b/src/client.c
@@ -53,7 +53,7 @@ send_command(enum command cmd, size_t n, const char *restrict msg)
{
struct sockaddr_un address;
int fd = -1, start = 1, status, outfd, goterr = 0;
- char *dir;
+ const char *dir;
pid_t pid;
ssize_t r, wrote;
char *buf = NULL;
@@ -97,7 +97,7 @@ send_command(enum command cmd, size_t n, const char *restrict msg)
/* Create socket. */
t ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) == -1);
- t (connect(fd, (struct sockaddr *)&address, sizeof(address)) == -1);
+ t (connect(fd, (struct sockaddr *)&address, (socklen_t)sizeof(address)) == -1);
/* Send message. */
t (write(fd, &cmd_, sizeof(cmd_)) < (ssize_t)sizeof(cmd_));
@@ -122,9 +122,8 @@ receive_again:
t (errno = 0, r == 0);
n -= (size_t)r;
for (dir = buf; r;) {
- t (wrote = write(outfd, dir, r), wrote <= 0);
- dir += (size_t)wrote;
- r -= (size_t)wrote;
+ t (wrote = write(outfd, dir, (size_t)r), wrote <= 0);
+ dir += wrote, r -= wrote;
}
}
free(buf), buf = NULL;
diff --git a/src/client.h b/src/client.h
index 9c10acf..22ff1ac 100644
--- a/src/client.h
+++ b/src/client.h
@@ -72,6 +72,9 @@ int send_command(enum command cmd, size_t n, const char *restrict msg);
* @param array The string array.
* @return The number of bytes required to store the array.
*/
+#ifdef __GNUC__
+__attribute__((__pure__))
+#endif
size_t measure_array(char *array[]);
/**
diff --git a/src/common.h b/src/common.h
index db642c2..375cf49 100644
--- a/src/common.h
+++ b/src/common.h
@@ -65,7 +65,7 @@ usage(void) \
* @param name:sitrng literal The name of the command.
*/
#define COMMAND(name) \
-char *argv0 = name;
+const char *argv0 = name;
/**
diff --git a/src/daemon.c b/src/daemon.c
index 6402473..a8278c4 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -44,7 +44,7 @@ extern char **environ;
char *buffer = buf; \
ssize_t r, n = 0; \
while (nbyte) { \
- r = FUN(fildes, buffer, nbyte, offset); \
+ r = FUN(fildes, buffer, nbyte, (off_t)offset); \
if (r < 0) return -1; \
if (r == 0) break; \
n += r; \
@@ -150,7 +150,7 @@ restore_array(char *buf, size_t len, size_t *n)
{
char **rc = malloc((len + 1) * sizeof(char*));
char **new = NULL;
- size_t i, e = 0;
+ size_t i = 0, e = 0;
t (!rc);
while (i < len) {
rc[e++] = buf + i;
@@ -346,7 +346,7 @@ found_it:
t (!(buf = malloc(n)));
t (r = preadn(STATE_FILENO, buf, n, off + sizeof(job) + job.n), r < 0);
t (pwriten(STATE_FILENO, buf, (size_t)r, off) < 0);
- t (ftruncate(STATE_FILENO, (size_t)r + off));
+ t (ftruncate(STATE_FILENO, (off_t)r + (off_t)off));
free(buf), buf = NULL;
fsync(STATE_FILENO);
diff --git a/src/daemonise.c b/src/daemonise.c
index 8d94a90..c9de08a 100644
--- a/src/daemonise.c
+++ b/src/daemonise.c
@@ -233,7 +233,7 @@ int daemonise(const char* name, int flags, ...)
if ((fd > 2) && (keepmax < fd))
keepmax = fd;
va_end(args);
- keep = calloc(keepmax + 1, sizeof(char));
+ keep = calloc((size_t)keepmax + 1, sizeof(char));
t (keep == NULL);
va_start(args, flags);
while ((fd = va_arg(args, int)) >= 0)
diff --git a/src/parse_time.c b/src/parse_time.c
index 323e746..7761557 100644
--- a/src/parse_time.c
+++ b/src/parse_time.c
@@ -85,10 +85,17 @@ const time_t timemax = (sizeof(time_t) == sizeof(long long int)) ? LLONG_MAX : L
static time_t
strtotime(const char *str, const char **end)
{
+#ifdef __GNUC__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wcast-qual"
+#endif
time_t rc;
long long int rcll;
long int rcl;
char **end_ = (char **)end;
+#ifdef __GNUC__
+# pragma GCC diagnostic pop
+#endif
if (!isdigit(*str))
FAIL(EINVAL);
diff --git a/src/satd-add.c b/src/satd-add.c
index 90d445c..f1fa4ed 100644
--- a/src/satd-add.c
+++ b/src/satd-add.c
@@ -65,16 +65,16 @@ main(int argc, char *argv[])
/* Update state file and run hook. */
t (flock(STATE_FILENO, LOCK_EX));
t (fstat(STATE_FILENO, &attr));
- t (r = preadn(STATE_FILENO, &(job->no), sizeof(job->no), 0), r < 0);
+ t (r = preadn(STATE_FILENO, &(job->no), sizeof(job->no), (size_t)0), r < 0);
if (r < (ssize_t)sizeof(job->no))
job->no = 0;
else
job->no += 1;
- t (pwriten(STATE_FILENO, &(job->no), sizeof(job->no), 0) < (ssize_t)sizeof(job->no));
+ t (pwriten(STATE_FILENO, &(job->no), sizeof(job->no), (size_t)0) < (ssize_t)sizeof(job->no));
if (attr.st_size < (off_t)sizeof(job->no))
attr.st_size = (off_t)sizeof(job->no);
n += sizeof(*job);
- t (pwriten(STATE_FILENO, job, n, attr.st_size) < (ssize_t)n);
+ t (pwriten(STATE_FILENO, job, n, (size_t)(attr.st_size)) < (ssize_t)n);
fsync(STATE_FILENO);
run_job_or_hook(job, "queued");
t (flock(STATE_FILENO, LOCK_UN));
diff --git a/src/satd-list.c b/src/satd-list.c
index 0a601dd..7605a50 100644
--- a/src/satd-list.c
+++ b/src/satd-list.c
@@ -71,7 +71,7 @@ quote(const char *str)
}
break;
- case 2:
+ default:
n = 4 * in + rn + sn + 2 * bn + 2 * qn + 3;
t (!(rc = malloc((n + 1) * sizeof(char))));
rc[i++] = '$';
@@ -107,9 +107,9 @@ strduration(char *buffer, time_t s)
{
char *buf = buffer;
int seconds, minutes, hours;
- seconds = s % 60, s /= 60;
- minutes = s % 60, s /= 60;
- hours = s % 24, s /= 24;
+ seconds = (int)(s % 60), s /= 60;
+ minutes = (int)(s % 60), s /= 60;
+ hours = (int)(s % 24), s /= 24;
if (s) {
buf += sprintf(buf, "%llid", (long long int)s);
buf += sprintf(buf, "%02i:", hours);
@@ -243,7 +243,7 @@ main(int argc, char *argv[])
{
size_t n = 0;
char *message = NULL;
- struct job **jobs;
+ struct job **jobs = NULL;
struct job **job;
DAEMON_PROLOGUE;
diff --git a/src/satd.c b/src/satd.c
index 98ea6a7..0a5fb3b 100644
--- a/src/satd.c
+++ b/src/satd.c
@@ -56,7 +56,7 @@ static int
create_socket(struct sockaddr_un *address)
{
int fd = -1, bound = 0;
- char *dir;
+ const char *dir;
int saved_errno;
/* Get socket address. */
@@ -87,7 +87,7 @@ create_socket(struct sockaddr_un *address)
does_not_exist:
t ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) == -1);
t (fchmod(fd, S_IRWXU) == -1);
- t (bind(fd, (struct sockaddr *)address, sizeof(*address)) == -1);
+ t (bind(fd, (struct sockaddr *)address, (socklen_t)sizeof(*address)) == -1);
/* EADDRINUSE just means that the file already exists, not that it is actually used. */
bound = 1;
@@ -196,9 +196,9 @@ int
main(int argc, char *argv[])
{
struct sockaddr_un address;
- int sock = -1, state = -1, foreground = 0, do_not_free = 0;
+ int sock = -1, state = -1, foreground = 0;
char *path = NULL;
- char *dir;
+ const char *dir;
/* Parse command line. */
if (argc > 0) argv0 = argv[0];
@@ -212,11 +212,8 @@ main(int argc, char *argv[])
t (path = hookpath("XDG_CONFIG_HOME", "/sat/hook"), !path && errno);
t (path = path ? path : hookpath("HOME", "/.config/sat/hook"), !path && errno);
t (path = path ? path : hookpath(NULL, "/.config/sat/hook"), !path && errno);
- path = path ? path : (do_not_free = 1, "/etc/sat/hook");
- t (setenv("SAT_HOOK_PATH", path, 1));
- if (!do_not_free)
- free(path);
- path = NULL;
+ t (setenv("SAT_HOOK_PATH", path ? path : "/etc/sat/hook", 1));
+ free(path), path = NULL;
}
/* Open/create state file. */
diff --git a/src/satq.c b/src/satq.c
index ba04bf3..048634d 100644
--- a/src/satq.c
+++ b/src/satq.c
@@ -45,7 +45,7 @@ main(int argc, char *argv[])
if (argc > 0) argv0 = argv[0];
if (argc > 1) usage();
- SEND(SAT_PRINT, 0, NULL);
+ SEND(SAT_PRINT, (size_t)0, NULL);
END(NULL);
}
diff --git a/src/satrm.c b/src/satrm.c
index 767782c..7904416 100644
--- a/src/satrm.c
+++ b/src/satrm.c
@@ -44,7 +44,7 @@ int
main(int argc, char *argv[])
{
size_t n;
- char *msg;
+ char *msg = NULL;
if (argc > 0) argv0 = argv[0];
if (argc < 2) usage();