mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:48:11 +00:00
Everywhere: Explicitly specify the size in StringView constructors
This commit moves the length calculations out to be directly on the StringView users. This is an important step towards the goal of removing StringView(char const*), as it moves the responsibility of calculating the size of the string to the user of the StringView (which will prevent naive uses causing OOB access).
This commit is contained in:
parent
e3da0adfe6
commit
c70f45ff44
75 changed files with 264 additions and 203 deletions
|
@ -110,7 +110,7 @@ String Shell::prompt() const
|
|||
builder.append(username);
|
||||
break;
|
||||
case 'h':
|
||||
builder.append(hostname);
|
||||
builder.append({ hostname, strlen(hostname) });
|
||||
break;
|
||||
case 'w': {
|
||||
String home_path = getenv("HOME");
|
||||
|
@ -1607,7 +1607,7 @@ Vector<Line::CompletionSuggestion> Shell::complete_variable(StringView name, siz
|
|||
|
||||
// Look at the environment.
|
||||
for (auto i = 0; environ[i]; ++i) {
|
||||
auto entry = StringView { environ[i] };
|
||||
StringView entry { environ[i], strlen(environ[i]) };
|
||||
if (entry.starts_with(pattern)) {
|
||||
auto parts = entry.split_view('=');
|
||||
if (parts.is_empty() || parts.first().is_empty())
|
||||
|
@ -2183,7 +2183,10 @@ Shell::Shell()
|
|||
// Add the default PATH vars.
|
||||
{
|
||||
StringBuilder path;
|
||||
path.append(getenv("PATH"));
|
||||
auto const* path_env_ptr = getenv("PATH");
|
||||
|
||||
if (path_env_ptr != NULL)
|
||||
path.append({ path_env_ptr, strlen(path_env_ptr) });
|
||||
if (path.length())
|
||||
path.append(":");
|
||||
path.append("/usr/local/sbin:/usr/local/bin:/usr/bin:/bin");
|
||||
|
@ -2476,7 +2479,8 @@ void Shell::timer_event(Core::TimerEvent& event)
|
|||
if (m_is_subshell)
|
||||
return;
|
||||
|
||||
StringView option = getenv("HISTORY_AUTOSAVE_TIME_MS");
|
||||
auto const* autosave_env_ptr = getenv("HISTORY_AUTOSAVE_TIME_MS");
|
||||
auto option = autosave_env_ptr != NULL ? StringView { autosave_env_ptr, strlen(autosave_env_ptr) } : StringView {};
|
||||
|
||||
auto time = option.to_uint();
|
||||
if (!time.has_value() || time.value() == 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue