summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile42
-rw-r--r--src/libpiano/piano.h9
-rw-r--r--src/libpiano/response.c31
-rw-r--r--src/player.c4
4 files changed, 40 insertions, 46 deletions
diff --git a/Makefile b/Makefile
index d2f2a8a..2867da1 100644
--- a/Makefile
+++ b/Makefile
@@ -167,32 +167,22 @@ clean:
all: pianobar
debug: pianobar
-debug: CFLAGS=-pedantic -ggdb -Wall -Wmissing-declarations -Wshadow -Wcast-qual \
- -Wformat=2 -Winit-self -Wignored-qualifiers -Wmissing-include-dirs \
- -Wfloat-equal -Wundef -Wpointer-arith -Wtype-limits -Wbad-function-cast \
- -Wcast-align -Wclobbered -Wempty-body -Wjump-misses-init -Waddress \
- -Wlogical-op -Waggregate-return -Wstrict-prototypes \
- -Wold-style-declaration -Wold-style-definition -Wmissing-parameter-type \
- -Wmissing-prototypes -Wmissing-field-initializers -Woverride-init \
- -Wpacked -Wredundant-decls -Wnested-externs
-# warnings for gcc 4.5; disabled:
-# -Wswitch-default: too many bogus warnings
-# -Wswitch-enum: too many bogus warnings
-# -Wunused-parameter: too many bogus warnings
-# -Wstrict-overflow: depends on optimization level
-# -Wunsafe-loop-optimizations: depends on optimization level
-# -Wwrite-strings: to be enabled
-# -Wconversion: too many (bogus?) warnings
-# -Wsign-conversion: same here
-# -Wsign-compare: to be enabled
-# -Wmissing-noreturn: recommendation
-# -Wmissing-format-attribute: same here
-# -Wpadded: have a closer look at this one
-# -Winline: we don't care
-# -Winvalid-pch: not our business
-# -Wdisabled-optimization: depends on optimization level
-# -Wstack-protector: we don't use stack protector
-# -Woverlength-strings: over-portability-ish
+debug: CC=clang
+debug: CFLAGS=-Wall -Wextra \
+ -pedantic \
+ -Wno-unused-parameter \
+ -fsanitize=address \
+ -fsanitize=integer \
+ -fsanitize=undefined \
+ -fsanitize=alignment \
+ -fsanitize=bool \
+ -fsanitize=bounds \
+ -fsanitize=enum \
+ -fsanitize=shift \
+ -fsanitize=signed-integer-overflow \
+ -fsanitize=unsigned-integer-overflow \
+ -fno-sanitize-recover
+debug: LDFLAGS=$(CFLAGS)
waitress-test: ${LIBWAITRESS_TEST_OBJ}
${CC} ${LDFLAGS} ${LIBWAITRESS_TEST_OBJ} ${LIBGNUTLS_LDFLAGS} -o waitress-test
diff --git a/src/libpiano/piano.h b/src/libpiano/piano.h
index ce66171..d8b84ce 100644
--- a/src/libpiano/piano.h
+++ b/src/libpiano/piano.h
@@ -310,14 +310,17 @@ size_t PianoListCount (const PianoListHead_t * const l);
#define PianoListCountP(l) PianoListCount(&(l)->head)
void *PianoListAppend (PianoListHead_t * const l, PianoListHead_t * const e)
__attribute__ ((warn_unused_result));
-#define PianoListAppendP(l,e) PianoListAppend(&(l)->head, &(e)->head)
+#define PianoListAppendP(l,e) PianoListAppend(((l) == NULL) ? NULL : &(l)->head, \
+ &(e)->head)
void *PianoListDelete (PianoListHead_t * const l, PianoListHead_t * const e)
__attribute__ ((warn_unused_result));
-#define PianoListDeleteP(l,e) PianoListDelete(&(l)->head, &(e)->head)
+#define PianoListDeleteP(l,e) PianoListDelete(((l) == NULL) ? NULL : &(l)->head, \
+ &(e)->head)
#define PianoListNextP(e) ((void *) (e)->head.next)
void *PianoListPrepend (PianoListHead_t * const l, PianoListHead_t * const e)
__attribute__ ((warn_unused_result));
-#define PianoListPrependP(l,e) PianoListPrepend (&(l)->head, &(e)->head)
+#define PianoListPrependP(l,e) PianoListPrepend (((l) == NULL) ? NULL : &(l)->head, \
+ &(e)->head)
void *PianoListGet (PianoListHead_t * const l, const size_t n);
#define PianoListGetP(l,n) PianoListGet (&(l)->head, n)
#define PianoListForeachP(l) for (; (l) != NULL; (l) = (void *) (l)->head.next)
diff --git a/src/libpiano/response.c b/src/libpiano/response.c
index 41bbfd3..53d22c1 100644
--- a/src/libpiano/response.c
+++ b/src/libpiano/response.c
@@ -130,9 +130,8 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
switch (reqData->step) {
case 0: {
/* decrypt timestamp */
- const char *cryptedTimestamp = json_object_get_string (
+ const char * const cryptedTimestamp = json_object_get_string (
json_object_object_get (result, "syncTime"));
- unsigned long timestamp = 0;
const time_t realTimestamp = time (NULL);
char *decryptedTimestamp = NULL;
size_t decryptedSize;
@@ -142,8 +141,10 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
cryptedTimestamp, &decryptedSize)) != NULL &&
decryptedSize > 4) {
/* skip four bytes garbage(?) at beginning */
- timestamp = strtoul (decryptedTimestamp+4, NULL, 0);
- ph->timeOffset = realTimestamp - timestamp;
+ const unsigned long timestamp = strtoul (
+ decryptedTimestamp+4, NULL, 0);
+ ph->timeOffset = (long int) realTimestamp -
+ (long int) timestamp;
ret = PIANO_RET_CONTINUE_REQUEST;
}
free (decryptedTimestamp);
@@ -177,7 +178,7 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
json_object *stations = json_object_object_get (result,
"stations"), *mix = NULL;
- for (size_t i=0; i < json_object_array_length (stations); i++) {
+ for (int i = 0; i < json_object_array_length (stations); i++) {
PianoStation_t *tmpStation;
json_object *s = json_object_array_get_idx (stations, i);
@@ -200,7 +201,7 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
if (mix != NULL) {
PianoStation_t *curStation = ph->stations;
PianoListForeachP (curStation) {
- for (size_t i = 0; i < json_object_array_length (mix); i++) {
+ for (int i = 0; i < json_object_array_length (mix); i++) {
json_object *id = json_object_array_get_idx (mix, i);
if (strcmp (json_object_get_string (id),
curStation->id) == 0) {
@@ -224,7 +225,7 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
json_object *items = json_object_object_get (result, "items");
assert (items != NULL);
- for (size_t i=0; i < json_object_array_length (items); i++) {
+ for (int i = 0; i < json_object_array_length (items); i++) {
json_object *s = json_object_array_get_idx (items, i);
PianoSong_t *song;
@@ -342,7 +343,7 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
/* get artists */
json_object *artists = json_object_object_get (result, "artists");
if (artists != NULL) {
- for (size_t i=0; i < json_object_array_length (artists); i++) {
+ for (int i = 0; i < json_object_array_length (artists); i++) {
json_object *a = json_object_array_get_idx (artists, i);
PianoArtist_t *artist;
@@ -361,7 +362,7 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
/* get songs */
json_object *songs = json_object_object_get (result, "songs");
if (songs != NULL) {
- for (size_t i=0; i < json_object_array_length (songs); i++) {
+ for (int i = 0; i < json_object_array_length (songs); i++) {
json_object *s = json_object_array_get_idx (songs, i);
PianoSong_t *song;
@@ -415,7 +416,7 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
/* get genre stations */
json_object *categories = json_object_object_get (result, "categories");
if (categories != NULL) {
- for (size_t i = 0; i < json_object_array_length (categories); i++) {
+ for (int i = 0; i < json_object_array_length (categories); i++) {
json_object *c = json_object_array_get_idx (categories, i);
PianoGenreCategory_t *tmpGenreCategory;
@@ -431,7 +432,7 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
json_object *stations = json_object_object_get (c,
"stations");
if (stations != NULL) {
- for (size_t k = 0;
+ for (int k = 0;
k < json_object_array_length (stations); k++) {
json_object *s =
json_object_array_get_idx (stations, k);
@@ -486,7 +487,7 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
sizeof (*reqData->retExplain));
strncpy (reqData->retExplain, "We're playing this track "
"because it features ", strSize);
- for (size_t i=0; i < json_object_array_length (explanations); i++) {
+ for (int i = 0; i < json_object_array_length (explanations); i++) {
json_object *e = json_object_array_get_idx (explanations,
i);
const char *s = json_object_get_string (
@@ -521,7 +522,7 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
/* songs */
json_object *songs = json_object_object_get (music, "songs");
if (songs != NULL) {
- for (size_t i = 0; i < json_object_array_length (songs); i++) {
+ for (int i = 0; i < json_object_array_length (songs); i++) {
json_object *s = json_object_array_get_idx (songs, i);
PianoSong_t *seedSong;
@@ -543,7 +544,7 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
json_object *artists = json_object_object_get (music,
"artists");
if (artists != NULL) {
- for (size_t i = 0; i < json_object_array_length (artists); i++) {
+ for (int i = 0; i < json_object_array_length (artists); i++) {
json_object *a = json_object_array_get_idx (artists, i);
PianoArtist_t *seedArtist;
@@ -566,7 +567,7 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
"feedback");
if (feedback != NULL) {
json_object_object_foreach (feedback, key, val) {
- for (size_t i = 0; i < json_object_array_length (val); i++) {
+ for (int i = 0; i < json_object_array_length (val); i++) {
json_object *s = json_object_array_get_idx (val, i);
PianoSong_t *feedbackSong;
diff --git a/src/player.c b/src/player.c
index 939b326..55b9e90 100644
--- a/src/player.c
+++ b/src/player.c
@@ -83,8 +83,8 @@ unsigned int BarPlayerCalcScale (const float applyGain) {
*/
static inline signed short int applyReplayGain (const signed short int value,
const unsigned int scale) {
- int tmpReplayBuf = value * scale;
- /* avoid clipping */
+ int tmpReplayBuf = value * (signed int) scale;
+ /* clipping */
if (tmpReplayBuf > SHRT_MAX*RG_SCALE_FACTOR) {
return SHRT_MAX;
} else if (tmpReplayBuf < SHRT_MIN*RG_SCALE_FACTOR) {