summaryrefslogtreecommitdiffstatshomepage
path: root/py/objstr.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-04 12:35:26 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-04 12:35:26 +0000
commit32f88410a153967af3f013d02a1a662aec19ec04 (patch)
treec6c30f9a8aae68def156d7564268e3928c00cb03 /py/objstr.c
parent2a5e6538b941d1fc9c1c0ef0bb0827b5ed2425d2 (diff)
parent0be78d44e59dd82eccde984a899d25bdf9afc093 (diff)
downloadmicropython-32f88410a153967af3f013d02a1a662aec19ec04.tar.gz
micropython-32f88410a153967af3f013d02a1a662aec19ec04.zip
Merge branch 'master' of github.com:dpgeorge/micropython
Diffstat (limited to 'py/objstr.c')
-rw-r--r--py/objstr.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c
index 59547e3cd6..54e6f37705 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -41,9 +41,20 @@ mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
int len = strlen(lhs_str);
if (start < 0) {
start = len + start;
+ if (start < 0) {
+ start = 0;
+ }
+ } else if (start > len) {
+ start = len;
}
if (stop <= 0) {
stop = len + stop;
+ // CPython returns empty string in such case
+ if (stop < 0) {
+ stop = start;
+ }
+ } else if (stop > len) {
+ stop = len;
}
return mp_obj_new_str(qstr_from_strn_copy(lhs_str + start, stop - start));
#endif