]> sigrok.org Git - libsigrokdecode.git/blobdiff - instance.c
irmp: introduce (part of) upstream IRMP sources
[libsigrokdecode.git] / instance.c
index 2859493194d724f7ea775cead7e6cba740742808..36088744893b7a76f8b0c74e8da33d977c3d3a13 100644 (file)
@@ -59,7 +59,8 @@ static void oldpins_array_seed(struct srd_decoder_inst *di)
        count = di->dec_num_channels;
        arr = g_array_sized_new(FALSE, TRUE, sizeof(uint8_t), count);
        g_array_set_size(arr, count);
-       memset(arr->data, SRD_INITIAL_PIN_SAME_AS_SAMPLE0, count);
+       if (arr->data)
+               memset(arr->data, SRD_INITIAL_PIN_SAME_AS_SAMPLE0, count);
        di->old_pins_array = arr;
 }
 
@@ -166,7 +167,7 @@ SRD_API int srd_inst_option_set(struct srd_decoder_inst *di,
                        }
                } else if (g_variant_is_of_type(value, G_VARIANT_TYPE_INT64)) {
                        val_int = g_variant_get_int64(value);
-                       if (!(py_optval = PyLong_FromLong(val_int))) {
+                       if (!(py_optval = PyLong_FromLongLong(val_int))) {
                                /* ValueError Exception */
                                PyErr_Clear();
                                srd_err("Option '%s' has invalid integer value.", sdo->id);
@@ -698,7 +699,7 @@ SRD_PRIV int srd_inst_start(struct srd_decoder_inst *di)
        Py_DECREF(py_res);
 
        /* Set self.samplenum to 0. */
-       py_samplenum = PyLong_FromLong(0);
+       py_samplenum = PyLong_FromUnsignedLongLong(0);
        PyObject_SetAttrString(di->py_inst, "samplenum", py_samplenum);
        Py_DECREF(py_samplenum);
 
@@ -831,6 +832,8 @@ static void update_old_pins_array(struct srd_decoder_inst *di,
 
        oldpins_array_seed(di);
        for (i = 0; i < di->dec_num_channels; i++) {
+               if (di->dec_channelmap[i] == -1)
+                       continue; /* Ignore unused optional channels. */
                byte_offset = di->dec_channelmap[i] / 8;
                bit_offset = di->dec_channelmap[i] % 8;
                sample = *(sample_pos + byte_offset) & (1 << bit_offset) ? 1 : 0;
@@ -853,6 +856,8 @@ static void update_old_pins_array_initial_pins(struct srd_decoder_inst *di)
        for (i = 0; i < di->dec_num_channels; i++) {
                if (di->old_pins_array->data[i] != SRD_INITIAL_PIN_SAME_AS_SAMPLE0)
                        continue;
+               if (di->dec_channelmap[i] == -1)
+                       continue; /* Ignore unused optional channels. */
                byte_offset = di->dec_channelmap[i] / 8;
                bit_offset = di->dec_channelmap[i] % 8;
                sample = *(sample_pos + byte_offset) & (1 << bit_offset) ? 1 : 0;
@@ -890,6 +895,8 @@ static gboolean all_terms_match(const struct srd_decoder_inst *di,
 
        for (l = cond; l; l = l->next) {
                term = l->data;
+               if (term->type == SRD_TERM_ALWAYS_FALSE)
+                       return FALSE;
                if (!term_matches(di, term, sample_pos))
                        return FALSE;
        }