From 01713e87d2fa473f6659184833a67aec281a19ed Mon Sep 17 00:00:00 2001 From: James Laird Date: Tue, 24 Jun 2014 22:29:02 +0200 Subject: [PATCH] Clean up compile warnings and default to -Wall. Hopefully this will make introducing new bugs more obvious. --- Makefile | 2 +- audio_pipe.c | 2 +- common.c | 1 + common.h | 7 +++++++ daemon.c | 6 +++--- mdns_external.c | 2 +- rtsp.c | 4 ++-- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 7dba8c2fd..a9a15186d 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ config.mk: $(MAKE) shairport endif -CFLAGS ?= -O2 +CFLAGS ?= -O2 -Wall -include config.mk PREFIX ?= /usr/local diff --git a/audio_pipe.c b/audio_pipe.c index b43d764ae..d48586a0c 100644 --- a/audio_pipe.c +++ b/audio_pipe.c @@ -44,7 +44,7 @@ static void start(int sample_rate) { } static void play(short buf[], int samples) { - write(fd, buf, samples*4); + write_unchecked(fd, buf, samples*4); } static void stop(void) { diff --git a/common.c b/common.c index 0bfbef100..c00f643cd 100644 --- a/common.c +++ b/common.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/common.h b/common.h index c3d270789..5aa8146fa 100644 --- a/common.h +++ b/common.h @@ -40,6 +40,13 @@ void die(char *format, ...); void warn(char *format, ...); void debug(int level, char *format, ...); +/* functions that ignore return values without compiler warnings. + * for use only where return values really don't matter! + */ +#define write_unchecked(...) (void)(write(__VA_ARGS__)+1) +#define read_unchecked(...) (void)(read (__VA_ARGS__)+1) +#define lockf_unchecked(...) (void)(lockf(__VA_ARGS__)+1) + uint8_t *base64_dec(char *input, int *outlen); char *base64_enc(uint8_t *input, int length); diff --git a/daemon.c b/daemon.c index f224a0794..a0bb3ccd7 100644 --- a/daemon.c +++ b/daemon.c @@ -56,7 +56,7 @@ void daemon_init() { exit(1); } else if (buf[0] != 0) { // First byte is non zero, child sent error message - write(STDERR_FILENO, buf, ret); + write_unchecked(STDERR_FILENO, buf, ret); fprintf(stderr, "\n"); exit(1); } else { @@ -86,7 +86,7 @@ void daemon_init() { void daemon_ready() { char ok = 0; - write(daemon_pipe[1], &ok, 1); + write_unchecked(daemon_pipe[1], &ok, 1); close(daemon_pipe[1]); daemon_pipe[1] = -1; } @@ -100,7 +100,7 @@ void daemon_fail(const char *format, va_list arg) { void daemon_exit() { if (lock_fd > 0) { - lockf(lock_fd, F_ULOCK, 0); + lockf_unchecked(lock_fd, F_ULOCK, 0); close(lock_fd); unlink(config.pidfile); lock_fd = -1; diff --git a/mdns_external.c b/mdns_external.c index ac329e7c2..fc22c532b 100644 --- a/mdns_external.c +++ b/mdns_external.c @@ -64,7 +64,7 @@ static int fork_execvp(const char *file, char *const argv[]) { // If we reach this point then execve has failed. // Write erno's value into the pipe and exit. - write(execpipe[1], &errno, sizeof(errno)); + write_unchecked(execpipe[1], &errno, sizeof(errno)); _exit(-1); return 0; // Just to make the compiler happy. diff --git a/rtsp.c b/rtsp.c index 938862d4b..b5d496697 100644 --- a/rtsp.c +++ b/rtsp.c @@ -356,7 +356,7 @@ static void msg_write_response(int fd, rtsp_message *resp) { die("Attempted to write overlong RTSP packet"); strcpy(p, "\r\n"); - write(fd, pkt, p-pkt+2); + write_unchecked(fd, pkt, p-pkt+2); } static void handle_options(rtsp_conn_info *conn, @@ -590,7 +590,7 @@ static char *make_nonce(void) { int fd = open("/dev/random", O_RDONLY); if (fd < 0) die("could not open /dev/random!"); - read(fd, random, sizeof(random)); + read_unchecked(fd, random, sizeof(random)); close(fd); return base64_enc(random, 8); }