mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 09:18:19 +00:00
strings: Return NUL from vim_strchr for invalid input
This commit is contained in:
@@ -428,16 +428,15 @@ int vim_strnicmp(const char *s1, const char *s2, size_t len)
|
|||||||
/// strchr() version which handles multibyte strings
|
/// strchr() version which handles multibyte strings
|
||||||
///
|
///
|
||||||
/// @param[in] string String to search in.
|
/// @param[in] string String to search in.
|
||||||
/// @param[in] c Character to search for. Must be a valid character.
|
/// @param[in] c Character to search for.
|
||||||
///
|
///
|
||||||
/// @return Pointer to the first byte of the found character in string or NULL
|
/// @return Pointer to the first byte of the found character in string or NULL
|
||||||
/// if it was not found. NUL character is never found, use `strlen()`
|
/// if it was not found or character is invalid. NUL character is never
|
||||||
/// instead.
|
/// found, use `strlen()` instead.
|
||||||
char_u *vim_strchr(const char_u *const string, const int c)
|
char_u *vim_strchr(const char_u *const string, const int c)
|
||||||
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
{
|
{
|
||||||
assert(c >= 0);
|
if (c <= 0) {
|
||||||
if (c == 0) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (c < 0x80) {
|
} else if (c < 0x80) {
|
||||||
return (char_u *)strchr((const char *)string, c);
|
return (char_u *)strchr((const char *)string, c);
|
||||||
|
Reference in New Issue
Block a user