diff --git a/py/objstr.c b/py/objstr.c
index 4f032d38c3653efab0aaa6e96287c9c5faa002a6..a7eb629be4515747f01bd099eb9d18d82f1ae540 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -519,8 +519,8 @@ STATIC inline mp_obj_t str_split_internal(mp_uint_t n_args, const mp_obj_t *args
                 s++;
             }
             mp_uint_t sub_len = s - start;
-            if (MP_LIKELY(!(len == 0 && s == top && (type && SPLITLINES)))) {
-                if (start + len != top && (type & KEEP)) {
+            if (MP_LIKELY(!(sub_len == 0 && s == top && (type && SPLITLINES)))) {
+                if (start + sub_len != top && (type & KEEP)) {
                     sub_len++;
                 }
                 mp_obj_list_append(res, mp_obj_new_str_of_type(self_type, start, sub_len));