py/qstr: Special case qstr_find_strn for empty string.
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>
This commit is contained in:
parent
9be0623d4c
commit
4212799fd8
|
@ -233,6 +233,11 @@ STATIC qstr qstr_add(mp_uint_t hash, mp_uint_t len, const char *q_ptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
qstr qstr_find_strn(const char *str, size_t str_len) {
|
qstr qstr_find_strn(const char *str, size_t str_len) {
|
||||||
|
if (str_len == 0) {
|
||||||
|
// strncmp behaviour is undefined for str==NULL.
|
||||||
|
return MP_QSTR_;
|
||||||
|
}
|
||||||
|
|
||||||
// work out hash of str
|
// work out hash of str
|
||||||
size_t str_hash = qstr_compute_hash((const byte *)str, str_len);
|
size_t str_hash = qstr_compute_hash((const byte *)str, str_len);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue