Skip to contentSkip to conversation

bindings: python: fix uninitialized default_vals being passed to gpiod_LineBulk_request()

PATCH Applied Kent Gibson 2 participants 2 messages Feb 15, 2021 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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)
---
 bindings/python/gpiodmodule.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
bindings/python/gpiodmodule.c +5 -3
index fee4c32..832787d 100644
@@ -1327,12 +1327,13 @@ static PyObject *gpiod_LineBulk_request(gpiod_LineBulkObject *self,
 				  NULL };
 
 	int rv, type = gpiod_LINE_REQ_DIR_AS_IS, flags = 0,
-	    default_vals[GPIOD_LINE_BULK_MAX_LINES], val;
+	    vals[GPIOD_LINE_BULK_MAX_LINES], val;
 	PyObject *def_vals_obj = NULL, *iter, *next;
 	struct gpiod_line_request_config conf;
 	struct gpiod_line_bulk bulk;
 	Py_ssize_t num_def_vals;
 	char *consumer = NULL;
+	const int *default_vals = NULL;
 	Py_ssize_t i;
 
 	if (gpiod_LineBulkOwnerIsClosed(self))
@@ -1348,7 +1349,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) {
@@ -1375,8 +1376,9 @@ static PyObject *gpiod_LineBulk_request(gpiod_LineBulkObject *self,
 				return NULL;
 			}
 
-			default_vals[i] = !!val;
+			vals[i] = !!val;
 		}
+		default_vals = vals;
 	}
 
 	Py_BEGIN_ALLOW_THREADS;
Signature · 1 line
2.30.0
#1 lore raw
Quoted 53 lines · Kent Gibson

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)
---
 bindings/python/gpiodmodule.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
bindings/python/gpiodmodule.c +5 -4
index fee4c32..832787d 100644
@@ -1327,12 +1327,13 @@ static PyObject *gpiod_LineBulk_request(gpiod_LineBulkObject *self,
                                  NULL };
 
        int rv, type = gpiod_LINE_REQ_DIR_AS_IS, flags = 0,
-           default_vals[GPIOD_LINE_BULK_MAX_LINES], val;
+           vals[GPIOD_LINE_BULK_MAX_LINES], val;
        PyObject *def_vals_obj = NULL, *iter, *next;
        struct gpiod_line_request_config conf;
        struct gpiod_line_bulk bulk;
        Py_ssize_t num_def_vals;
        char *consumer = NULL;
+       const int *default_vals = NULL;
        Py_ssize_t i;
 
        if (gpiod_LineBulkOwnerIsClosed(self))
@@ -1348,7 +1349,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) {
@@ -1375,8 +1376,9 @@ static PyObject *gpiod_LineBulk_request(gpiod_LineBulkObject *self,
                                return NULL;
                        }
 
-                       default_vals[i] = !!val;
+                       vals[i] = !!val;
                }
+               default_vals = vals;
        }
 
        Py_BEGIN_ALLOW_THREADS;
--
Quoted 2 lines

2.30.0

Applied, thanks!

Bartosz