From: Kent Gibson Date: Mon, 15 Feb 2021 14:39:19 +0000 (+0100) Subject: bindings: python: fix uninitialized default_vals being passed to gpiod_LineBulk_request() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=94b6b59b2b4d4b9563a7d0c37ed5bdd14652e262;p=qemu-gpiodev%2Flibgpiod.git bindings: python: fix uninitialized default_vals being passed to gpiod_LineBulk_request() If "default_vals" is not provided in the kwds then default_vals are passed uninitialized to gpiod_line_request_bulk(), so rename the existing default_vals to vals and introduce a new default_vals that points to vals, or NULL if no defaults have been passed. Fixes: 96c524c4951c (bindings: implement python bindings) Reported-by: Pedro Botella Signed-off-by: Kent Gibson Signed-off-by: Bartosz Golaszewski --- diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c index a6a336e..02514cc 100644 --- a/bindings/python/gpiodmodule.c +++ b/bindings/python/gpiodmodule.c @@ -1310,9 +1310,10 @@ static PyObject *gpiod_LineBulk_request(gpiod_LineBulkObject *self, NULL }; int rv, type = gpiod_LINE_REQ_DIR_AS_IS, flags = 0, - default_vals[LINE_REQUEST_MAX_LINES], val; + vals[LINE_REQUEST_MAX_LINES], val; PyObject *def_vals_obj = NULL, *iter, *next; struct gpiod_line_request_config conf; + const int *default_vals = NULL; struct gpiod_line_bulk *bulk; Py_ssize_t num_def_vals; char *consumer = NULL; @@ -1334,7 +1335,7 @@ static PyObject *gpiod_LineBulk_request(gpiod_LineBulkObject *self, gpiod_MakeRequestConfig(&conf, consumer, type, flags); if (def_vals_obj) { - memset(default_vals, 0, sizeof(default_vals)); + memset(vals, 0, sizeof(vals)); num_def_vals = PyObject_Size(def_vals_obj); if (num_def_vals != self->num_lines) { @@ -1361,8 +1362,9 @@ static PyObject *gpiod_LineBulk_request(gpiod_LineBulkObject *self, return NULL; } - default_vals[i] = !!val; + vals[i] = !!val; } + default_vals = vals; } bulk = gpiod_LineBulkObjToCLineBulk(self);