From 2377246220f2d48e341e5b1286a44818eab789d8 Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Tue, 18 Sep 2018 23:21:40 +0200 Subject: [PATCH] Fix various gcc 8 compiler warnings related to ARRAY_SIZE. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Example: In file included from src/hardware/kecheng-kc-330b/protocol.h:26, from src/hardware/kecheng-kc-330b/api.c:22: src/hardware/kecheng-kc-330b/api.c: In function ‘config_list’: src/libsigrok-internal.h:51:34: warning: division ‘sizeof (void *) / sizeof (void)’ does not compute the number of array elements [-Wsizeof-pointer-div] #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) ^ src/libsigrok-internal.h:55:32: note: in expansion of macro ‘ARRAY_SIZE’ #define ARRAY_AND_SIZE(a) (a), ARRAY_SIZE(a) ^~~~~~~~~~ src/libsigrok-internal.h:964:43: note: in expansion of macro ‘ARRAY_AND_SIZE’ std_opts_config_list(key, data, sdi, cg, ARRAY_AND_SIZE(scanopts), \ ^~~~~~~~~~~~~~ src/hardware/kecheng-kc-330b/api.c:296:10: note: in expansion of macro ‘STD_CONFIG_LIST’ return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); ^~~~~~~~~~~~~~~ --- src/hardware/asix-sigma/api.c | 2 +- src/hardware/baylibre-acme/api.c | 2 +- src/hardware/hung-chang-dso-2100/api.c | 4 ++-- src/hardware/ikalogic-scanalogic2/api.c | 2 +- src/hardware/ikalogic-scanaplus/api.c | 2 +- src/hardware/kecheng-kc-330b/api.c | 2 +- src/hardware/lecroy-logicstudio/api.c | 2 +- src/hardware/lecroy-xstream/api.c | 4 ++-- src/hardware/link-mso19/api.c | 2 +- src/hardware/pipistrello-ols/api.c | 2 +- src/hardware/zeroplus-logic-cube/api.c | 2 +- src/libsigrok-internal.h | 2 ++ src/session_driver.c | 2 +- src/std.c | 8 +++++--- 14 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/hardware/asix-sigma/api.c b/src/hardware/asix-sigma/api.c index 8e1a490a..89783456 100644 --- a/src/hardware/asix-sigma/api.c +++ b/src/hardware/asix-sigma/api.c @@ -226,7 +226,7 @@ static int config_list(uint32_t key, GVariant **data, { switch (key) { case SR_CONF_DEVICE_OPTIONS: - return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); + return STD_CONFIG_LIST(key, data, sdi, cg, NO_OPTS, drvopts, devopts); case SR_CONF_SAMPLERATE: *data = std_gvar_samplerates(samplerates, samplerates_count); break; diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index 5dd05c57..ebaf3e5a 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -216,7 +216,7 @@ static int config_list(uint32_t key, GVariant **data, if (!cg) { switch (key) { case SR_CONF_DEVICE_OPTIONS: - return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); + return STD_CONFIG_LIST(key, data, sdi, cg, NO_OPTS, drvopts, devopts); case SR_CONF_SAMPLERATE: *data = std_gvar_samplerates_steps(ARRAY_AND_SIZE(samplerates)); break; diff --git a/src/hardware/hung-chang-dso-2100/api.c b/src/hardware/hung-chang-dso-2100/api.c index e0806070..f3d94d20 100644 --- a/src/hardware/hung-chang-dso-2100/api.c +++ b/src/hardware/hung-chang-dso-2100/api.c @@ -490,10 +490,10 @@ static int config_list(uint32_t key, GVariant **data, switch (key) { case SR_CONF_SCAN_OPTIONS: - return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, NULL); + return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NO_OPTS, NO_OPTS); case SR_CONF_DEVICE_OPTIONS: if (!cg) - return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); + return STD_CONFIG_LIST(key, data, sdi, cg, NO_OPTS, drvopts, devopts); *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg)); break; case SR_CONF_SAMPLERATE: diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index 9a84a767..b911f03d 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -299,7 +299,7 @@ static int config_list(uint32_t key, GVariant **data, { switch (key) { case SR_CONF_DEVICE_OPTIONS: - return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); + return STD_CONFIG_LIST(key, data, sdi, cg, NO_OPTS, drvopts, devopts); case SR_CONF_SAMPLERATE: *data = std_gvar_samplerates(ARRAY_AND_SIZE(sl2_samplerates)); break; diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index fe77104d..f29e5c39 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -253,7 +253,7 @@ static int config_list(uint32_t key, GVariant **data, { switch (key) { case SR_CONF_DEVICE_OPTIONS: - return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); + return STD_CONFIG_LIST(key, data, sdi, cg, NO_OPTS, drvopts, devopts); case SR_CONF_SAMPLERATE: *data = std_gvar_samplerates(ARRAY_AND_SIZE(samplerates)); break; diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index 44c0c292..28368404 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -293,7 +293,7 @@ static int config_list(uint32_t key, GVariant **data, { switch (key) { case SR_CONF_DEVICE_OPTIONS: - return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); + return STD_CONFIG_LIST(key, data, sdi, cg, NO_OPTS, drvopts, devopts); case SR_CONF_SAMPLE_INTERVAL: *data = std_gvar_tuple_array(ARRAY_AND_SIZE(kecheng_kc_330b_sample_intervals)); break; diff --git a/src/hardware/lecroy-logicstudio/api.c b/src/hardware/lecroy-logicstudio/api.c index e75b5b09..6425e0f5 100644 --- a/src/hardware/lecroy-logicstudio/api.c +++ b/src/hardware/lecroy-logicstudio/api.c @@ -410,7 +410,7 @@ static int config_list(uint32_t key, GVariant **data, { switch (key) { case SR_CONF_DEVICE_OPTIONS: - return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); + return STD_CONFIG_LIST(key, data, sdi, cg, NO_OPTS, drvopts, devopts); case SR_CONF_SAMPLERATE: *data = std_gvar_samplerates(ARRAY_AND_SIZE(samplerates)); break; diff --git a/src/hardware/lecroy-xstream/api.c b/src/hardware/lecroy-xstream/api.c index 8c034944..8551351a 100644 --- a/src/hardware/lecroy-xstream/api.c +++ b/src/hardware/lecroy-xstream/api.c @@ -315,10 +315,10 @@ static int config_list(uint32_t key, GVariant **data, switch (key) { case SR_CONF_SCAN_OPTIONS: - return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, NULL); + return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NO_OPTS, NO_OPTS); case SR_CONF_DEVICE_OPTIONS: if (!cg) - return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); + return STD_CONFIG_LIST(key, data, sdi, cg, NO_OPTS, drvopts, devopts); *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog)); break; case SR_CONF_COUPLING: diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index 923867e3..dd3ff3c8 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -284,7 +284,7 @@ static int config_list(int key, GVariant **data, { switch (key) { case SR_CONF_DEVICE_OPTIONS: - return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); + return STD_CONFIG_LIST(key, data, sdi, cg, NO_OPTS, drvopts, devopts); case SR_CONF_SAMPLERATE: *data = std_gvar_samplerates_steps(ARRAY_AND_SIZE(samplerates)); break; diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index 33339d6b..8d8fe5a9 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -325,7 +325,7 @@ static int config_list(uint32_t key, GVariant **data, switch (key) { case SR_CONF_DEVICE_OPTIONS: - return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); + return STD_CONFIG_LIST(key, data, sdi, cg, NO_OPTS, drvopts, devopts); case SR_CONF_SAMPLERATE: *data = std_gvar_samplerates_steps(ARRAY_AND_SIZE(samplerates)); break; diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index c2d1424b..4ebe152f 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -395,7 +395,7 @@ static int config_list(uint32_t key, GVariant **data, switch (key) { case SR_CONF_DEVICE_OPTIONS: - return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); + return STD_CONFIG_LIST(key, data, sdi, cg, NO_OPTS, drvopts, devopts); case SR_CONF_SAMPLERATE: devc = sdi->priv; if (devc->prof->max_sampling_freq == 100) diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index a681abae..f3e4d335 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -960,6 +960,8 @@ SR_PRIV int std_opts_config_list(uint32_t key, GVariant **data, const uint32_t scanopts[], size_t scansize, const uint32_t drvopts[], size_t drvsize, const uint32_t devopts[], size_t devsize); +extern SR_PRIV const uint32_t NO_OPTS[1]; + #define STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts) \ std_opts_config_list(key, data, sdi, cg, ARRAY_AND_SIZE(scanopts), \ ARRAY_AND_SIZE(drvopts), ARRAY_AND_SIZE(devopts)) diff --git a/src/session_driver.c b/src/session_driver.c index 66618a1d..79383cc7 100644 --- a/src/session_driver.c +++ b/src/session_driver.c @@ -328,7 +328,7 @@ static int config_set(uint32_t key, GVariant *data, static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts); + return STD_CONFIG_LIST(key, data, sdi, cg, NO_OPTS, NO_OPTS, devopts); } static int dev_acquisition_start(const struct sr_dev_inst *sdi) diff --git a/src/std.c b/src/std.c index 9199611a..6a6c80ad 100644 --- a/src/std.c +++ b/src/std.c @@ -39,6 +39,8 @@ #define LOG_PREFIX "std" +SR_PRIV const uint32_t NO_OPTS[1] = {}; + /** * Standard driver init() callback API helper. * @@ -581,7 +583,7 @@ SR_PRIV int std_opts_config_list(uint32_t key, GVariant **data, switch (key) { case SR_CONF_SCAN_OPTIONS: /* Always return scanopts, regardless of sdi or cg. */ - if (!scanopts) + if (!scanopts || scanopts == NO_OPTS) return SR_ERR_ARG; *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, scanopts, scansize, sizeof(uint32_t)); @@ -589,13 +591,13 @@ SR_PRIV int std_opts_config_list(uint32_t key, GVariant **data, case SR_CONF_DEVICE_OPTIONS: if (!sdi) { /* sdi == NULL: return drvopts. */ - if (!drvopts) + if (!drvopts || drvopts == NO_OPTS) return SR_ERR_ARG; *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, drvopts, drvsize, sizeof(uint32_t)); } else if (sdi && !cg) { /* sdi != NULL, cg == NULL: return devopts. */ - if (!devopts) + if (!devopts || devopts == NO_OPTS) return SR_ERR_ARG; *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, devopts, devsize, sizeof(uint32_t));