-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
py/qstr: Special case qstr_find_strn for empty string. #12894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Code size report:
|
Codecov Report
@@ Coverage Diff @@
## master #12894 +/- ##
=======================================
Coverage 98.39% 98.39%
=======================================
Files 158 158
Lines 20971 20972 +1
=======================================
+ Hits 20635 20636 +1
Misses 336 336
|
@@ -110,8 +110,9 @@ char *strchr(const char *s, int c) { | |||
} | |||
|
|||
int strncmp(const char *s1, const char *s2, size_t n) { | |||
while (*s1 && *s2 && n-- > 0) { | |||
while (n > 0 && *s1 && *s2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, this actually fixes the case when n=0
is passed in to this function, with both strings non-null.
C99 says that strncmp has UB for either string being NULL, so the current behavior is technically correct, but it's an easy fix to handle this case correctly. 7.1.4: "unless explicitly stated otherwise in the detailed description... if an argument to a function has ...null pointer.. the behavior is undefined". 7.21.1: "Unless explicitly stated otherwise in the description of a particular function in this subclause, pointer arguments on such a call shall still have valid values, as described in 7.1.4". Also make the same change for the minimal version in bare-arm/lib.c. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This handles the case where an empty bytes/bytearray/str could pass in NULL as the str argument (with length zero). This would result in UB in strncmp. Even though our bare-metal implementation of strncmp handles this, best to avoid it for when we're using system strncmp. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
5b604e5
to
4212799
Compare
Reported here: #12853 (comment)