Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
d6cf5c67
Commit
d6cf5c67
authored
6 years ago
by
Jeff Epler
Committed by
Damien George
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
py/objstr: In find/rfind, don't crash when end < start.
parent
b9c78425
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
py/objstr.c
+5
-0
5 additions, 0 deletions
py/objstr.c
tests/basics/string_find.py
+1
-0
1 addition, 0 deletions
tests/basics/string_find.py
tests/basics/string_rfind.py
+1
-0
1 addition, 0 deletions
tests/basics/string_rfind.py
with
7 additions
and
0 deletions
py/objstr.c
+
5
−
0
View file @
d6cf5c67
...
...
@@ -699,8 +699,13 @@ STATIC mp_obj_t str_finder(size_t n_args, const mp_obj_t *args, int direction, b
end
=
str_index_to_ptr
(
self_type
,
haystack
,
haystack_len
,
args
[
3
],
true
);
}
if
(
end
<
start
)
{
goto
out_error
;
}
const
byte
*
p
=
find_subbytes
(
start
,
end
-
start
,
needle
,
needle_len
,
direction
);
if
(
p
==
NULL
)
{
out_error:
// not found
if
(
is_index
)
{
mp_raise_ValueError
(
"substring not found"
);
...
...
This diff is collapsed.
Click to expand it.
tests/basics/string_find.py
+
1
−
0
View file @
d6cf5c67
...
...
@@ -21,6 +21,7 @@ print("0000".find('-1', 3))
print
(
"
0000
"
.
find
(
'
1
'
,
3
))
print
(
"
0000
"
.
find
(
'
1
'
,
4
))
print
(
"
0000
"
.
find
(
'
1
'
,
5
))
print
(
"
aaaaaaaaaaa
"
.
find
(
"
bbb
"
,
9
,
2
))
try
:
'
abc
'
.
find
(
1
)
...
...
This diff is collapsed.
Click to expand it.
tests/basics/string_rfind.py
+
1
−
0
View file @
d6cf5c67
...
...
@@ -21,3 +21,4 @@ print("0000".rfind('-1', 3))
print
(
"
0000
"
.
rfind
(
'
1
'
,
3
))
print
(
"
0000
"
.
rfind
(
'
1
'
,
4
))
print
(
"
0000
"
.
rfind
(
'
1
'
,
5
))
print
(
"
aaaaaaaaaaa
"
.
rfind
(
"
bbb
"
,
9
,
2
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment