]> git.alsa-project.org Git - alsa-python.git/commitdiff
alsaseq: fix 'ext' buffer fill
authorFrançois Laignel <fengalin@free.fr>
Sun, 7 Mar 2021 19:00:19 +0000 (20:00 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 31 May 2022 13:49:08 +0000 (15:49 +0200)
The `GETDICTEXT` macro used to perfom one pass on the provided int
list to check the actual item types brefore allocating and filling
the target buffer. The python list was not read again causing the
buffer to be filled with the last value read during the type check.

This patch performs the type check as well as buffer fill in one go.
The buffer is freed if an item is found to be of a wrong type.

Fixes: https://github.com/alsa-project/alsa-python/pull/3
Signed-off-by: François Laignel <fengalin@free.fr>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
pyalsa/alsaseq.c

index e3b76a23471d9bfa12adf959a93e981adcfd6ffb..b2959fbf0e0606f44382016b693629ac5ad36a12 100644 (file)
       int len = PyList_Size(list);                                     \
       self->event->data.ext.len = len;                                 \
       if (len > 0) {                                                   \
+       self->buff = malloc(len);                                       \
+       if (self->buff == NULL) {                                       \
+         PyErr_SetString(PyExc_TypeError,                              \
+                       name " no memory");                             \
+         self->event->data.ext.len = 0;                                \
+         return NULL;                                                  \
+       }                                                               \
        int i;                                                          \
        long val;                                                       \
        for (i = 0; i < len; i++) {                                     \
            PyErr_SetString(PyExc_TypeError,                            \
                            name " must be a list of integers");        \
            self->event->data.ext.len = 0;                              \
-            return NULL;                                               \
+           free(self->buff);                                           \
+           self->buff = NULL;                                          \
+           return NULL;                                                \
          }                                                             \
-       }                                                               \
-       self->buff = malloc(len);                                       \
-       if (self->buff == NULL) {                                       \
-         PyErr_SetString(PyExc_TypeError,                              \
-                       name " no memory");                             \
-         self->event->data.ext.len = 0;                                \
-         return NULL;                                                  \
-       }                                                               \
-       for (i = 0; i < len; i++)                                       \
          self->buff[i] = val;                                          \
+       }                                                               \
        self->event->data.ext.ptr = self->buff;                         \
       }                                                                        \
     }                                                                  \