Skip to content

Commit 5ccf66a

Browse files
lemirecodebytere
authored andcommitted
fix: bad usage of std::string_view::npos
Co-authored-by: codebytere <shelley.vohr@gmail.com>
1 parent 9a5f916 commit 5ccf66a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

include/ada/helpers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ ada_really_inline void remove_ascii_tab_or_newline(std::string& input) noexcept;
8282

8383
/**
8484
* @private
85-
* Return the substring from input going from index pos to the end. If pos >
86-
* input.size(), it returns an empty string_view. This function cannot throw.
85+
* Return the substring from input going from index pos to the end.
86+
* This function cannot throw.
8787
*/
8888
ada_really_inline std::string_view substring(std::string_view input,
8989
size_t pos) noexcept;

src/helpers.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ ada_really_inline bool shorten_path(std::string& path,
106106
// If url’s scheme is "file", path’s size is 1, and path[0] is a normalized
107107
// Windows drive letter, then return.
108108
if (type == ada::scheme::type::FILE &&
109-
first_delimiter == std::string_view::npos) {
109+
first_delimiter == std::string_view::npos && !path.empty()) {
110110
if (checkers::is_normalized_windows_drive_letter(
111-
std::string_view(path.data() + 1, first_delimiter - 1))) {
111+
helpers::substring(path, 1))) {
112112
return false;
113113
}
114114
}
@@ -130,9 +130,9 @@ ada_really_inline bool shorten_path(std::string_view& path,
130130
// If url’s scheme is "file", path’s size is 1, and path[0] is a normalized
131131
// Windows drive letter, then return.
132132
if (type == ada::scheme::type::FILE &&
133-
first_delimiter == std::string_view::npos) {
133+
first_delimiter == std::string_view::npos && !path.empty()) {
134134
if (checkers::is_normalized_windows_drive_letter(
135-
std::string_view(path.data() + 1, first_delimiter - 1))) {
135+
helpers::substring(path, 1))) {
136136
return false;
137137
}
138138
}

0 commit comments

Comments
 (0)