From 72d70b0f4836cef074aab4cb6e6b29dbb42da801 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 17 Mar 2020 11:37:56 +0100 Subject: [PATCH] Add and fix some more warnings Fixes #216 --- meson.build | 6 ++++++ pipewire-jack/src/pipewire-jack.c | 5 +++-- spa/include/spa/utils/defs.h | 4 ++-- spa/include/spa/utils/hook.h | 9 ++++++--- spa/plugins/alsa/alsa-pcm.c | 2 +- spa/plugins/bluez5/a2dp-sink.c | 7 +++++-- spa/plugins/bluez5/a2dp-source.c | 7 +++++-- src/modules/module-protocol-native.c | 4 ++-- src/modules/module-rtkit.c | 8 ++++---- 9 files changed, 34 insertions(+), 18 deletions(-) diff --git a/meson.build b/meson.build index d7a5a27a3..8cc60c7d8 100644 --- a/meson.build +++ b/meson.build @@ -53,6 +53,12 @@ if cc.get_id() == 'gcc' '-Wpointer-arith', '-Wformat-security', '-Werror=suggest-attribute=format', + '-Wmissing-braces', + '-Wno-missing-field-initializers', + '-Wno-unused-parameter', + '-Wtype-limits', + '-Wold-style-declaration', + '-Wvariadic-macros', # '-DSPA_DEBUG_MEMCPY', # '-DFASTPATH', language : 'c') diff --git a/pipewire-jack/src/pipewire-jack.c b/pipewire-jack/src/pipewire-jack.c index 0bc6d3dc7..5b7776803 100644 --- a/pipewire-jack/src/pipewire-jack.c +++ b/pipewire-jack/src/pipewire-jack.c @@ -1572,7 +1572,8 @@ static int client_node_port_use_buffers(void *object, struct client *c = (struct client *) object; struct port *p = GET_PORT(c, direction, port_id); struct buffer *b; - uint32_t i, j, fl, res; + uint32_t i, j, fl; + int res; struct mix *mix; if (!p->valid) { @@ -4593,7 +4594,7 @@ jack_midi_data_t* jack_midi_event_reserve(void *port_buffer, buffer_size = mb->buffer_size; - if (SPA_UNLIKELY(time < 0 || time >= mb->nframes)) { + if (SPA_UNLIKELY(time >= mb->nframes)) { pw_log_warn("midi %p: time:%d frames:%d", port_buffer, time, mb->nframes); goto failed; } diff --git a/spa/include/spa/utils/defs.h b/spa/include/spa/utils/defs.h index 9d4273adb..3e007d0d8 100644 --- a/spa/include/spa/utils/defs.h +++ b/spa/include/spa/utils/defs.h @@ -176,8 +176,8 @@ struct spa_fraction { #endif #endif -#define SPA_STRINGIFY_1(x...) #x -#define SPA_STRINGIFY(x...) SPA_STRINGIFY_1(x) +#define SPA_STRINGIFY_1(...) #__VA_ARGS__ +#define SPA_STRINGIFY(...) SPA_STRINGIFY_1(__VA_ARGS__) #define spa_return_if_fail(expr) \ do { \ diff --git a/spa/include/spa/utils/hook.h b/spa/include/spa/utils/hook.h index 7490644e2..63bf50255 100644 --- a/spa/include/spa/utils/hook.h +++ b/spa/include/spa/utils/hook.h @@ -51,6 +51,9 @@ struct spa_callbacks { void *data; }; +/** Check if a callback \c has method \m of version \v */ +#define SPA_CALLBACK_CHECK(c,m,v) ((c) && ((v) == 0 || (c)->version > (v)-1) && (c)->m) + #define SPA_CALLBACKS_INIT(_funcs,_data) (struct spa_callbacks){ _funcs, _data, } struct spa_interface { @@ -133,14 +136,14 @@ spa_hook_list_join(struct spa_hook_list *list, #define spa_callbacks_call(callbacks,type,method,vers,...) \ ({ \ const type *_f = (const type *) (callbacks)->funcs; \ - if (SPA_LIKELY(_f && _f->version >= (vers) && _f->method)) \ + if (SPA_LIKELY(SPA_CALLBACK_CHECK(_f,method,vers))) \ _f->method((callbacks)->data, ## __VA_ARGS__); \ }) #define spa_callbacks_call_res(callbacks,type,res,method,vers,...) \ ({ \ const type *_f = (const type *) (callbacks)->funcs; \ - if (SPA_LIKELY(_f && _f->version >= (vers) && _f->method)) \ + if (SPA_LIKELY(SPA_CALLBACK_CHECK(_f,method,vers))) \ res = _f->method((callbacks)->data, ## __VA_ARGS__); \ res; \ }) @@ -171,7 +174,7 @@ spa_hook_list_join(struct spa_hook_list *list, spa_list_cursor_start(cursor, s, link); \ spa_list_for_each_cursor(ci, cursor, &list->list, link) { \ const type *_f = (const type *)ci->cb.funcs; \ - if (SPA_LIKELY(_f && _f->version >= (vers) && _f->method)) { \ + if (SPA_LIKELY(SPA_CALLBACK_CHECK(_f,method,vers))) { \ _f->method(ci->cb.data, ## __VA_ARGS__); \ count++; \ if (once) \ diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 059366e2f..d6ff40138 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -199,7 +199,7 @@ static void sanitize_map(snd_pcm_chmap_t* map) uint32_t i, j, pos; for (i = 0; i < map->channels; i++) { - if (map->pos[i] < 0 || map->pos[i] > SND_CHMAP_LAST) + if (map->pos[i] > SND_CHMAP_LAST) map->pos[i] = SND_CHMAP_UNKNOWN; p = 1LL << map->pos[i]; diff --git a/spa/plugins/bluez5/a2dp-sink.c b/spa/plugins/bluez5/a2dp-sink.c index 882b58e0b..38dd1f292 100644 --- a/spa/plugins/bluez5/a2dp-sink.c +++ b/spa/plugins/bluez5/a2dp-sink.c @@ -1045,12 +1045,15 @@ impl_node_port_enum_params(void *object, int seq, { a2dp_sbc_t *config = this->transport->configuration; struct spa_audio_info_raw info = { 0, }; + int res; info.format = SPA_AUDIO_FORMAT_S16; - if ((info.rate = a2dp_sbc_get_frequency(config)) < 0) + if ((res = a2dp_sbc_get_frequency(config)) < 0) return -EIO; - if ((info.channels = a2dp_sbc_get_channels(config)) < 0) + info.rate = res; + if ((res = a2dp_sbc_get_channels(config)) < 0) return -EIO; + info.channels = res; switch (info.channels) { case 1: diff --git a/spa/plugins/bluez5/a2dp-source.c b/spa/plugins/bluez5/a2dp-source.c index e4d312f88..16e35fce9 100644 --- a/spa/plugins/bluez5/a2dp-source.c +++ b/spa/plugins/bluez5/a2dp-source.c @@ -702,12 +702,15 @@ impl_node_port_enum_params(void *object, int seq, { a2dp_sbc_t *config = this->transport->configuration; struct spa_audio_info_raw info = { 0, }; + int res; info.format = SPA_AUDIO_FORMAT_S16; - if ((info.rate = a2dp_sbc_get_frequency(config)) < 0) + if ((res = a2dp_sbc_get_frequency(config)) < 0) return -EIO; - if ((info.channels = a2dp_sbc_get_channels(config)) < 0) + info.rate = res; + if ((res = a2dp_sbc_get_channels(config)) < 0) return -EIO; + info.channels = res; switch (info.channels) { case 1: diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index e5d16dcfd..7ea3c8551 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -1046,7 +1046,7 @@ error: return NULL; } -const static struct pw_protocol_implementaton protocol_impl = { +static const struct pw_protocol_implementaton protocol_impl = { PW_VERSION_PROTOCOL_IMPLEMENTATION, .new_client = impl_new_client, .add_server = impl_add_server, @@ -1105,7 +1105,7 @@ static int impl_ext_end_resource(struct pw_resource *resource, struct pw_impl_client *client = resource->client; return client->send_seq = pw_protocol_native_connection_end(data->connection, builder); } -const static struct pw_protocol_native_ext protocol_ext_impl = { +static const struct pw_protocol_native_ext protocol_ext_impl = { PW_VERSION_PROTOCOL_NATIVE_EXT, .begin_proxy = impl_ext_begin_proxy, .add_proxy_fd = impl_ext_add_proxy_fd, diff --git a/src/modules/module-rtkit.c b/src/modules/module-rtkit.c index 1bc11bc58..23be7566e 100644 --- a/src/modules/module-rtkit.c +++ b/src/modules/module-rtkit.c @@ -283,7 +283,7 @@ int pw_rtkit_get_min_nice_level(struct pw_rtkit_bus *connection, int *min_nice_l return err; } -long unsigned int pw_rtkit_get_rttime_usec_max(struct pw_rtkit_bus *connection) +long long pw_rtkit_get_rttime_usec_max(struct pw_rtkit_bus *connection) { long long retval; int err; @@ -453,7 +453,7 @@ static void idle_func(struct spa_source *source) struct pw_rtkit_bus *system_bus; struct rlimit rl; int r, rtprio; - long unsigned int rttime; + long long rttime; uint64_t count; spa_system_eventfd_read(impl->system, impl->source.fd, &count); @@ -485,8 +485,8 @@ static void idle_func(struct spa_source *source) rttime = pw_rtkit_get_rttime_usec_max(system_bus); if (rttime >= 0) { - rl.rlim_cur = SPA_MIN(rl.rlim_cur, rttime); - rl.rlim_max = SPA_MIN(rl.rlim_max, rttime); + rl.rlim_cur = SPA_MIN(rl.rlim_cur, (long unsigned int)rttime); + rl.rlim_max = SPA_MIN(rl.rlim_max, (long unsigned int)rttime); } pw_log_debug("rt.prio:%d rt.time.soft:%lu rt.time.hard:%lu",