]> sigrok.org Git - libsigrok.git/commitdiff
Fix various gcc 8 compiler warnings related to ARRAY_SIZE.
authorUwe Hermann <redacted>
Tue, 18 Sep 2018 21:21:40 +0000 (23:21 +0200)
committerUwe Hermann <redacted>
Sat, 6 Oct 2018 17:13:39 +0000 (19:13 +0200)
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);
            ^~~~~~~~~~~~~~~

14 files changed:
src/hardware/asix-sigma/api.c
src/hardware/baylibre-acme/api.c
src/hardware/hung-chang-dso-2100/api.c
src/hardware/ikalogic-scanalogic2/api.c
src/hardware/ikalogic-scanaplus/api.c
src/hardware/kecheng-kc-330b/api.c
src/hardware/lecroy-logicstudio/api.c
src/hardware/lecroy-xstream/api.c
src/hardware/link-mso19/api.c
src/hardware/pipistrello-ols/api.c
src/hardware/zeroplus-logic-cube/api.c
src/libsigrok-internal.h
src/session_driver.c
src/std.c

index 8e1a490aa345ee6e91ea8a968236d0899c2ad8cf..89783456c5bbe416ed5fcc8c3945eb9093400181 100644 (file)
@@ -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;
index 5dd05c579417ff0db39aa8f4825e7c9d16ce36c8..ebaf3e5a674a07db20b3b0dac2ece3ee5bf15237 100644 (file)
@@ -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;
index e0806070922d4e72bdcd46846e30c67115f592c3..f3d94d2003d386de64760e37d31d4499f20b2bb0 100644 (file)
@@ -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:
index 9a84a767ed283fc50a7eb4ad2a4a56e8809a8dfe..b911f03d182b224cd9a48c5db8edb50a99e349ff 100644 (file)
@@ -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;
index fe77104d300ef593d46a2b23f214910be9d1637a..f29e5c39ae327c24b37a4ade4047cecc4410bc98 100644 (file)
@@ -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;
index 44c0c29297bb8d1d33a8ce845da3cf224b556443..2836840446d0842dc433af475da8849fcc1503f6 100644 (file)
@@ -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;
index e75b5b09e97bc5a1d7090b9b6b9e484a87aba125..6425e0f5fcedaeb95cdbbcedb545b165dcf952fd 100644 (file)
@@ -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;
index 8c034944eb3b435301cbe0c7dc7bde3dd11af9d8..8551351a11a2994270879e9b461b566e08881e70 100644 (file)
@@ -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:
index 923867e38abd300969cf2f55f829eaffd77a13bd..dd3ff3c80c8923195b18f253f16f4b560f0f61cd 100644 (file)
@@ -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;
index 33339d6bcc86eb7250c5ff9b0880cd0a29d66fb4..8d8fe5a9e697500280e216e46bdb3b67d9b28a3b 100644 (file)
@@ -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;
index c2d1424b428872e00798bc3583abe7c33eb0f438..4ebe152f151ab075b4f53fc0276d50836d6e6b98 100644 (file)
@@ -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)
index a681abae43def87dc8919ca2b79c9c05d618d166..f3e4d335ce2248199b9f2cdda016a3c9021fda5a 100644 (file)
@@ -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))
index 66618a1ddb65ac170a3576039f6d05a5389e4a83..79383cc719fb011aab5758b1ad471d64324abb0b 100644 (file)
@@ -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)
index 9199611a1723118cf39de5d857679f17388d2f4c..6a6c80adfff5df1f8b93bfec89a6267fe1ee6a9f 100644 (file)
--- 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));