Skip to content

Commit

Permalink
Clean up compile warnings and default to -Wall.
Browse files Browse the repository at this point in the history
Hopefully this will make introducing new bugs more obvious.
  • Loading branch information
abrasive committed Jun 24, 2014
1 parent 7a06bf8 commit 01713e8
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ config.mk:
$(MAKE) shairport
endif

CFLAGS ?= -O2
CFLAGS ?= -O2 -Wall
-include config.mk

PREFIX ?= /usr/local
Expand Down
2 changes: 1 addition & 1 deletion audio_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include <memory.h>
#include <unistd.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/evp.h>
Expand Down
7 changes: 7 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion mdns_external.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions rtsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 01713e8

Please sign in to comment.