]> sigrok.org Git - libsigrokdecode.git/commitdiff
Use PyLong_FromUnsignedLongLong() where needed.
authorUwe Hermann <redacted>
Fri, 22 May 2020 11:06:26 +0000 (13:06 +0200)
committerUwe Hermann <redacted>
Fri, 22 May 2020 11:06:26 +0000 (13:06 +0200)
There were a few places where PyLong_FromLong() was used for uint64_t
numbers. Properly use PyLong_FromUnsignedLongLong() there, and also
fix a few additional size/signedness issues while we're here.

Reported (and partial patch provided) by "The Count" on Bugzilla, thanks!

This fixes bug #1499.

instance.c
type_decoder.c

index 5264bd0bd3a54d72f8503e926931f542ab310d96..36088744893b7a76f8b0c74e8da33d977c3d3a13 100644 (file)
@@ -167,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);
@@ -699,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);
 
index 983400bacb0070fd07826c10c5ed397f17f36555..1b378f1ac6e8b53d2e037310c60bd659923ee0b1 100644 (file)
@@ -605,13 +605,13 @@ static PyObject *get_current_pinvalues(const struct srd_decoder_inst *di)
                /* A channelmap value of -1 means "unused optional channel". */
                if (di->dec_channelmap[i] == -1) {
                        /* Value of unused channel is 0xff, instead of 0 or 1. */
-                       PyTuple_SetItem(py_pinvalues, i, PyLong_FromLong(0xff));
+                       PyTuple_SetItem(py_pinvalues, i, PyLong_FromUnsignedLong(0xff));
                } else {
                        sample_pos = di->inbuf + ((di->abs_cur_samplenum - di->abs_start_samplenum) * di->data_unitsize);
                        byte_offset = di->dec_channelmap[i] / 8;
                        bit_offset = di->dec_channelmap[i] % 8;
                        sample = *(sample_pos + byte_offset) & (1 << bit_offset) ? 1 : 0;
-                       PyTuple_SetItem(py_pinvalues, i, PyLong_FromLong(sample));
+                       PyTuple_SetItem(py_pinvalues, i, PyLong_FromUnsignedLong(sample));
                }
        }
 
@@ -922,7 +922,7 @@ static PyObject *Decoder_wait(PyObject *self, PyObject *args)
                /* If there's a match, set self.samplenum etc. and return. */
                if (found_match) {
                        /* Set self.samplenum to the (absolute) sample number that matched. */
-                       py_samplenum = PyLong_FromLong(di->abs_cur_samplenum);
+                       py_samplenum = PyLong_FromUnsignedLongLong(di->abs_cur_samplenum);
                        PyObject_SetAttrString(di->py_inst, "samplenum", py_samplenum);
                        Py_DECREF(py_samplenum);