]> sigrok.org Git - libsigrok.git/commitdiff
yokogawa-dlm: silence compiler warning (passing an empty array)
authorGerhard Sittig <redacted>
Tue, 17 Oct 2023 19:25:00 +0000 (21:25 +0200)
committerGerhard Sittig <redacted>
Wed, 18 Oct 2023 19:35:13 +0000 (21:35 +0200)
Rephrase the config_list() routine such that it does not attempt to
access the first item in an empty array. Be explicit about the digital
channel group's devopts being empty by design, add a comment.

The compiler warning could have been a false positive, but phrasing the
source code differently doesn't harm either, eliminates uncertainty.

src/hardware/yokogawa-dlm/api.c

index f80e83dceb7e91537252d05b37a516e12e225ac3..c1fe1b019e0a27ae4d1b251a2ef6726c01d862b1 100644 (file)
@@ -53,6 +53,7 @@ static const uint32_t devopts_cg_analog[] = {
 };
 
 static const uint32_t devopts_cg_digital[] = {
+       /* EMPTY */
 };
 
 enum {
@@ -423,12 +424,19 @@ static int config_list(uint32_t key, GVariant **data,
 
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
-               if (cg_type == CG_ANALOG)
+               if (cg_type == CG_ANALOG) {
                        *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog));
-               else if (cg_type == CG_DIGITAL)
+                       break;
+               }
+               if (cg_type == CG_DIGITAL) {
+                       if (!ARRAY_SIZE(devopts_cg_digital)) {
+                               *data = std_gvar_array_u32(NULL, 0);
+                               break;
+                       }
                        *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_digital));
-               else
-                       *data = std_gvar_array_u32(NULL, 0);
+                       break;
+               }
+               *data = std_gvar_array_u32(NULL, 0);
                break;
        case SR_CONF_COUPLING:
                if (!cg)