summaryrefslogtreecommitdiffstatshomepage
path: root/py/objstr.c
diff options
context:
space:
mode:
authorJohn R. Lenton <jlenton@gmail.com>2014-01-13 23:09:04 +0000
committerJohn R. Lenton <jlenton@gmail.com>2014-01-13 23:09:04 +0000
commitf5a0a7d2b30d390f03dd0b6f8866ec619d2c5ee3 (patch)
treeae93f78ed97e4d820150a7b0d8c026f94cfb790e /py/objstr.c
parent189c8e1cc46896382b6d19da8b89a4cc4f7e3864 (diff)
parentca318bba0d97c66d8fb14a089d8fa269a0e1b424 (diff)
downloadmicropython-f5a0a7d2b30d390f03dd0b6f8866ec619d2c5ee3.tar.gz
micropython-f5a0a7d2b30d390f03dd0b6f8866ec619d2c5ee3.zip
Merge remote-tracking branch 'upstream/master' into containment
Diffstat (limited to 'py/objstr.c')
-rw-r--r--py/objstr.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/py/objstr.c b/py/objstr.c
index 4151cf007b..8b7ab9692f 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -178,8 +178,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;
@@ -192,14 +192,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) {