From 558fd5d228d3c610958c4aae41b1ede0b6487c35 Mon Sep 17 00:00:00 2001
From: Paul Sokolovsky <pfalcon@users.sourceforge.net>
Date: Sun, 10 Apr 2016 13:36:44 +0300
Subject: [PATCH] py/stream: ioctl(): Properly support 2-arg form.

---
 py/stream.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/py/stream.c b/py/stream.c
index fcdd6be72..0fb57118c 100644
--- a/py/stream.c
+++ b/py/stream.c
@@ -414,12 +414,14 @@ STATIC mp_obj_t stream_ioctl(size_t n_args, const mp_obj_t *args) {
     const mp_stream_p_t *stream_p = mp_get_stream_raise(args[0], MP_STREAM_OP_IOCTL);
 
     mp_buffer_info_t bufinfo;
-    uintptr_t val;
-    if (MP_OBJ_IS_INT(args[2])) {
-        val = mp_obj_get_int(args[2]);
-    } else {
-        mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ);
-        val = (uintptr_t)bufinfo.buf;
+    uintptr_t val = 0;
+    if (n_args > 2) {
+        if (MP_OBJ_IS_INT(args[2])) {
+            val = mp_obj_get_int(args[2]);
+        } else {
+            mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE);
+            val = (uintptr_t)bufinfo.buf;
+        }
     }
 
     int error;
-- 
GitLab