diff options
author | John R. Lenton <jlenton@gmail.com> | 2014-01-13 23:14:35 +0000 |
---|---|---|
committer | John R. Lenton <jlenton@gmail.com> | 2014-01-13 23:14:35 +0000 |
commit | 93451002f04e0b89e41e1faa82f86e937bb219f1 (patch) | |
tree | 478f8fedae2b08f12181c98a4a3d1c4cdf19403d /py/objstr.c | |
parent | 88cb1e60e0b780d71e9c2d7b0acafa71ba3ea318 (diff) | |
parent | ca318bba0d97c66d8fb14a089d8fa269a0e1b424 (diff) | |
download | micropython-93451002f04e0b89e41e1faa82f86e937bb219f1.tar.gz micropython-93451002f04e0b89e41e1faa82f86e937bb219f1.zip |
Merge remote-tracking branch 'upstream/master' into builtins
Conflicts:
py/builtin.c
py/builtin.h
py/runtime.c
Diffstat (limited to 'py/objstr.c')
-rw-r--r-- | py/objstr.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/py/objstr.c b/py/objstr.c index be1f00e686..f48bde6001 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -169,8 +169,8 @@ static mp_obj_t str_find(int n_args, const mp_obj_t *args) { const char* haystack = qstr_str(((mp_obj_str_t*)args[0])->qstr); const char* needle = qstr_str(((mp_obj_str_t*)args[1])->qstr); - ssize_t haystack_len = strlen(haystack); - ssize_t needle_len = strlen(needle); + size_t haystack_len = strlen(haystack); + size_t needle_len = strlen(needle); size_t start = 0; size_t end = haystack_len; @@ -183,14 +183,17 @@ static mp_obj_t str_find(int n_args, const mp_obj_t *args) { } char *p = strstr(haystack + start, needle); - ssize_t pos = -1; - if (p) { - pos = p - haystack; + if (p == NULL) { + // not found + return MP_OBJ_NEW_SMALL_INT(-1); + } else { + // found + machine_int_t pos = p - haystack; if (pos + needle_len > end) { pos = -1; } + return MP_OBJ_NEW_SMALL_INT(pos); } - return MP_OBJ_NEW_SMALL_INT(pos); } mp_obj_t str_strip(int n_args, const mp_obj_t *args) { |