diff options
-rw-r--r-- | AK/JsonParser.cpp | 2 | ||||
-rw-r--r-- | AK/String.cpp | 2 | ||||
-rw-r--r-- | AK/StringBuilder.cpp | 4 | ||||
-rw-r--r-- | AK/StringView.cpp | 2 | ||||
-rw-r--r-- | Applications/Help/main.cpp | 2 | ||||
-rw-r--r-- | Kernel/Scheduler.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibCore/ProcessStatisticsReader.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibGUI/TextDocument.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibGUI/TextDocument.h | 10 | ||||
-rw-r--r-- | Libraries/LibGUI/TextEditor.cpp | 3 | ||||
-rw-r--r-- | Libraries/LibIPC/ClientConnection.h | 4 | ||||
-rw-r--r-- | Libraries/LibIPC/ServerConnection.h | 4 | ||||
-rw-r--r-- | Shell/LineEditor.cpp | 74 | ||||
-rw-r--r-- | Userland/man.cpp | 2 | ||||
-rw-r--r-- | Userland/md.cpp | 2 |
15 files changed, 60 insertions, 57 deletions
diff --git a/AK/JsonParser.cpp b/AK/JsonParser.cpp index 2f21e3b04b..b99bb91bd5 100644 --- a/AK/JsonParser.cpp +++ b/AK/JsonParser.cpp @@ -130,7 +130,7 @@ String JsonParser::consume_quoted_string() return String::empty(); auto& last_string_starting_with_character = m_last_string_starting_with_character[(u8)buffer.first()]; - if (last_string_starting_with_character.length() == (size_t)buffer.size()) { + if (last_string_starting_with_character.length() == buffer.size()) { if (!memcmp(last_string_starting_with_character.characters(), buffer.data(), buffer.size())) return last_string_starting_with_character; } diff --git a/AK/String.cpp b/AK/String.cpp index 980b346867..131ba9e70f 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -143,7 +143,7 @@ Vector<String> String::split_limit(char separator, size_t limit, bool keep_empty Vector<String> v; size_t substart = 0; - for (size_t i = 0; i < length() && ((size_t)v.size() + 1) != limit; ++i) { + for (size_t i = 0; i < length() && (v.size() + 1) != limit; ++i) { char ch = characters()[i]; if (ch == separator) { size_t sublen = i - substart; diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index da97a970c8..28f89098f5 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -33,8 +33,8 @@ namespace AK { inline void StringBuilder::will_append(size_t size) { - if ((m_length + size) > (size_t)m_buffer.size()) - m_buffer.grow(max((size_t)16, (size_t)m_buffer.size() * 2 + size)); + if ((m_length + size) > m_buffer.size()) + m_buffer.grow(max(static_cast<size_t>(16), m_buffer.size() * 2 + size)); } StringBuilder::StringBuilder(size_t initial_capacity) diff --git a/AK/StringView.cpp b/AK/StringView.cpp index 6f8af57d10..0dcd8e5b54 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -40,7 +40,7 @@ StringView::StringView(const String& string) StringView::StringView(const ByteBuffer& buffer) : m_characters((const char*)buffer.data()) - , m_length((size_t)buffer.size()) + , m_length(buffer.size()) { } diff --git a/Applications/Help/main.cpp b/Applications/Help/main.cpp index 2af401b9c9..010a87f0e5 100644 --- a/Applications/Help/main.cpp +++ b/Applications/Help/main.cpp @@ -122,7 +122,7 @@ int main(int argc, char* argv[]) return; } auto buffer = file->read_all(); - StringView source { (const char*)buffer.data(), (size_t)buffer.size() }; + StringView source { (const char*)buffer.data(), buffer.size() }; MDDocument md_document; bool success = md_document.parse(source); diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index b9c2540202..a5aa46f089 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -599,7 +599,7 @@ void Scheduler::timer_tick(RegisterState& regs) sample.pid = Process::current->pid(); sample.tid = Thread::current->tid(); sample.timestamp = g_uptime; - for (size_t i = 0; i < min((size_t)backtrace.size(), Profiling::max_stack_frame_count); ++i) { + for (size_t i = 0; i < min(backtrace.size(), Profiling::max_stack_frame_count); ++i) { sample.frames[i] = backtrace[i]; } } diff --git a/Libraries/LibCore/ProcessStatisticsReader.cpp b/Libraries/LibCore/ProcessStatisticsReader.cpp index ed7616a9d0..cd87e00e31 100644 --- a/Libraries/LibCore/ProcessStatisticsReader.cpp +++ b/Libraries/LibCore/ProcessStatisticsReader.cpp @@ -47,7 +47,7 @@ HashMap<pid_t, Core::ProcessStatistics> ProcessStatisticsReader::get_all() HashMap<pid_t, Core::ProcessStatistics> map; auto file_contents = file->read_all(); - auto json = JsonValue::from_string({ file_contents.data(), (size_t)file_contents.size() }); + auto json = JsonValue::from_string(file_contents); json.as_array().for_each([&](auto& value) { const JsonObject& process_object = value.as_object(); Core::ProcessStatistics process; diff --git a/Libraries/LibGUI/TextDocument.cpp b/Libraries/LibGUI/TextDocument.cpp index 51d7323cd8..a303824a63 100644 --- a/Libraries/LibGUI/TextDocument.cpp +++ b/Libraries/LibGUI/TextDocument.cpp @@ -86,7 +86,7 @@ void TextDocument::set_text(const StringView& text) size_t TextDocumentLine::first_non_whitespace_column() const { for (size_t i = 0; i < length(); ++i) { - if (!isspace(m_text[(int)i])) + if (!isspace(m_text[i])) return i; } return length(); diff --git a/Libraries/LibGUI/TextDocument.h b/Libraries/LibGUI/TextDocument.h index 51234450b7..76ce03d23a 100644 --- a/Libraries/LibGUI/TextDocument.h +++ b/Libraries/LibGUI/TextDocument.h @@ -75,9 +75,9 @@ public: static NonnullRefPtr<TextDocument> create(Client* client = nullptr); ~TextDocument(); - size_t line_count() const { return (size_t)m_lines.size(); } - const TextDocumentLine& line(size_t line_index) const { return m_lines[(int)line_index]; } - TextDocumentLine& line(size_t line_index) { return m_lines[(int)line_index]; } + size_t line_count() const { return m_lines.size(); } + const TextDocumentLine& line(size_t line_index) const { return m_lines[line_index]; } + TextDocumentLine& line(size_t line_index) { return m_lines[line_index]; } void set_spans(const Vector<TextDocumentSpan>& spans) { m_spans = spans; } @@ -88,7 +88,7 @@ public: bool has_spans() const { return !m_spans.is_empty(); } const Vector<TextDocumentSpan>& spans() const { return m_spans; } - void set_span_at_index(size_t index, TextDocumentSpan span) { m_spans[(int)index] = move(span); } + void set_span_at_index(size_t index, TextDocumentSpan span) { m_spans[index] = move(span); } void append_line(NonnullOwnPtr<TextDocumentLine>); void remove_line(size_t line_index); @@ -156,7 +156,7 @@ public: StringView view() const { return { characters(), (size_t)length() }; } const char* characters() const { return m_text.data(); } - size_t length() const { return (size_t)m_text.size() - 1; } + size_t length() const { return m_text.size() - 1; } void set_text(TextDocument&, const StringView&); void append(TextDocument&, char); void prepend(TextDocument&, char); diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp index fa501d3f95..6ee66b43f5 100644 --- a/Libraries/LibGUI/TextEditor.cpp +++ b/Libraries/LibGUI/TextEditor.cpp @@ -559,7 +559,8 @@ void TextEditor::move_selected_lines_down() get_selection_line_boundaries(first_line, last_line); auto& lines = document().lines(); - if (last_line >= (size_t)(lines.size() - 1)) + ASSERT(lines.size() != 0); + if (last_line >= lines.size() - 1) return; lines.insert((int)first_line, lines.take((int)last_line + 1)); diff --git a/Libraries/LibIPC/ClientConnection.h b/Libraries/LibIPC/ClientConnection.h index 12207e4a2b..d1a7803425 100644 --- a/Libraries/LibIPC/ClientConnection.h +++ b/Libraries/LibIPC/ClientConnection.h @@ -108,7 +108,7 @@ public: auto buffer = message.encode(); - int nwritten = write(m_socket->fd(), buffer.data(), (size_t)buffer.size()); + int nwritten = write(m_socket->fd(), buffer.data(), buffer.size()); if (nwritten < 0) { switch (errno) { case EPIPE: @@ -149,7 +149,7 @@ public: } size_t decoded_bytes = 0; - for (size_t index = 0; index < (size_t)bytes.size(); index += decoded_bytes) { + for (size_t index = 0; index < bytes.size(); index += decoded_bytes) { auto remaining_bytes = ByteBuffer::wrap(bytes.data() + index, bytes.size() - index); auto message = Endpoint::decode_message(remaining_bytes, decoded_bytes); if (!message) { diff --git a/Libraries/LibIPC/ServerConnection.h b/Libraries/LibIPC/ServerConnection.h index db3bb53aff..bd8dfad71b 100644 --- a/Libraries/LibIPC/ServerConnection.h +++ b/Libraries/LibIPC/ServerConnection.h @@ -121,7 +121,7 @@ public: bool post_message(const Message& message) { auto buffer = message.encode(); - int nwritten = write(m_connection->fd(), buffer.data(), (size_t)buffer.size()); + int nwritten = write(m_connection->fd(), buffer.data(), buffer.size()); if (nwritten < 0) { perror("write"); ASSERT_NOT_REACHED(); @@ -165,7 +165,7 @@ private: } size_t decoded_bytes = 0; - for (size_t index = 0; index < (size_t)bytes.size(); index += decoded_bytes) { + for (size_t index = 0; index < bytes.size(); index += decoded_bytes) { auto remaining_bytes = ByteBuffer::wrap(bytes.data() + index, bytes.size() - index); if (auto message = LocalEndpoint::decode_message(remaining_bytes, decoded_bytes)) { m_unprocessed_messages.append(move(message)); diff --git a/Shell/LineEditor.cpp b/Shell/LineEditor.cpp index 27336bb954..84b97384be 100644 --- a/Shell/LineEditor.cpp +++ b/Shell/LineEditor.cpp @@ -66,21 +66,21 @@ void LineEditor::insert(const String& string) fputs(string.characters(), stdout); fflush(stdout); - if (m_cursor == (size_t)m_buffer.size()) { - m_buffer.append(string.characters(), (int)string.length()); - m_cursor = (size_t)m_buffer.size(); + if (m_cursor == m_buffer.size()) { + m_buffer.append(string.characters(), string.length()); + m_cursor = m_buffer.size(); return; } vt_save_cursor(); vt_clear_to_end_of_line(); - for (size_t i = m_cursor; i < (size_t)m_buffer.size(); ++i) - fputc(m_buffer[(int)i], stdout); + for (size_t i = m_cursor; i < m_buffer.size(); ++i) + fputc(m_buffer[i], stdout); vt_restore_cursor(); - m_buffer.ensure_capacity(m_buffer.size() + (int)string.length()); + m_buffer.ensure_capacity(m_buffer.size() + string.length()); for (size_t i = 0; i < string.length(); ++i) - m_buffer.insert((int)m_cursor + (int)i, string[i]); + m_buffer.insert(m_cursor + i, string[i]); m_cursor += string.length(); } @@ -89,19 +89,19 @@ void LineEditor::insert(const char ch) putchar(ch); fflush(stdout); - if (m_cursor == (size_t)m_buffer.size()) { + if (m_cursor == m_buffer.size()) { m_buffer.append(ch); - m_cursor = (size_t)m_buffer.size(); + m_cursor = m_buffer.size(); return; } vt_save_cursor(); vt_clear_to_end_of_line(); - for (size_t i = m_cursor; i < (size_t)m_buffer.size(); ++i) - fputc(m_buffer[(int)i], stdout); + for (size_t i = m_cursor; i < m_buffer.size(); ++i) + fputc(m_buffer[i], stdout); vt_restore_cursor(); - m_buffer.insert((int)m_cursor, ch); + m_buffer.insert(m_cursor, ch); ++m_cursor; } @@ -173,7 +173,7 @@ Vector<String> LineEditor::tab_complete_first_token(const String& token) if (completion.length() > token.length()) insert(completion.substring(token.length(), completion.length() - token.length())); // If we have a single match, we add a space, unless we already have one. - if (!seen_others && (m_cursor == (size_t)m_buffer.size() || m_buffer[(int)m_cursor] != ' ')) + if (!seen_others && (m_cursor == m_buffer.size() || m_buffer[m_cursor] != ' ')) insert(' '); return suggestions; @@ -184,18 +184,20 @@ Vector<String> LineEditor::tab_complete_other_token(String& token) String path; Vector<String> suggestions; - int last_slash = (int)token.length() - 1; + ASSERT(token.length() != 0); + + ssize_t last_slash = token.length() - 1; while (last_slash >= 0 && token[last_slash] != '/') --last_slash; if (last_slash >= 0) { // Split on the last slash. We'll use the first part as the directory // to search and the second part as the token to complete. - path = token.substring(0, (size_t)last_slash + 1); + path = token.substring(0, last_slash + 1); if (path[0] != '/') path = String::format("%s/%s", g.cwd.characters(), path.characters()); path = canonicalized_path(path); - token = token.substring((size_t)last_slash + 1, token.length() - (size_t)last_slash - 1); + token = token.substring(last_slash + 1, token.length() - last_slash - 1); } else { // We have no slashes, so the directory to search is the current // directory and the token to complete is just the original token. @@ -247,7 +249,7 @@ Vector<String> LineEditor::tab_complete_other_token(String& token) if (!stat_error) { if (S_ISDIR(program_status.st_mode)) insert('/'); - else if (m_cursor == (size_t)m_buffer.size() || m_buffer[(int)m_cursor] != ' ') + else if (m_cursor == m_buffer.size() || m_buffer[m_cursor] != ' ') insert(' '); } } @@ -297,17 +299,17 @@ String LineEditor::get_line(const String& prompt) } auto do_delete = [&] { - if (m_cursor == (size_t)m_buffer.size()) { + if (m_cursor == m_buffer.size()) { fputc('\a', stdout); fflush(stdout); return; } - m_buffer.remove((int)m_cursor - 1); + m_buffer.remove(m_cursor - 1); fputs("\033[3~", stdout); fflush(stdout); vt_save_cursor(); vt_clear_to_end_of_line(); - for (size_t i = m_cursor; i < (size_t)m_buffer.size(); ++i) + for (size_t i = m_cursor; i < m_buffer.size(); ++i) fputc(m_buffer[i], stdout); vt_restore_cursor(); }; @@ -353,7 +355,7 @@ String LineEditor::get_line(const String& prompt) m_state = InputState::Free; continue; case 'C': // right - if (m_cursor < (size_t)m_buffer.size()) { + if (m_cursor < m_buffer.size()) { ++m_cursor; fputs("\033[C", stdout); fflush(stdout); @@ -369,10 +371,10 @@ String LineEditor::get_line(const String& prompt) m_state = InputState::Free; continue; case 'F': - if (m_cursor < (size_t)m_buffer.size()) { - fprintf(stdout, "\033[%zuC", (size_t)m_buffer.size() - m_cursor); + if (m_cursor < m_buffer.size()) { + fprintf(stdout, "\033[%zuC", m_buffer.size() - m_cursor); fflush(stdout); - m_cursor = (size_t)m_buffer.size(); + m_cursor = m_buffer.size(); } m_state = InputState::Free; continue; @@ -398,10 +400,10 @@ String LineEditor::get_line(const String& prompt) } if (ch == '\t') { - bool is_empty_token = m_cursor == 0 || m_buffer[(int)m_cursor - 1] == ' '; + bool is_empty_token = m_cursor == 0 || m_buffer[m_cursor - 1] == ' '; m_times_tab_pressed++; - int token_start = (int)m_cursor - 1; + int token_start = m_cursor - 1; if (!is_empty_token) { while (token_start >= 0 && m_buffer[token_start] != ' ') --token_start; @@ -416,7 +418,7 @@ String LineEditor::get_line(const String& prompt) } } - String token = is_empty_token ? String() : String(&m_buffer[token_start], m_cursor - (size_t)token_start); + String token = is_empty_token ? String() : String(&m_buffer[token_start], m_cursor - token_start); Vector<String> suggestions; if (is_first_token) @@ -463,13 +465,13 @@ String LineEditor::get_line(const String& prompt) fflush(stdout); return; } - m_buffer.remove((int)m_cursor - 1); + m_buffer.remove(m_cursor - 1); --m_cursor; putchar(8); vt_save_cursor(); vt_clear_to_end_of_line(); - for (size_t i = m_cursor; i < (size_t)m_buffer.size(); ++i) - fputc(m_buffer[(int)i], stdout); + for (size_t i = m_cursor; i < m_buffer.size(); ++i) + fputc(m_buffer[i], stdout); vt_restore_cursor(); }; @@ -480,7 +482,7 @@ String LineEditor::get_line(const String& prompt) if (ch == g.termios.c_cc[VWERASE]) { bool has_seen_nonspace = false; while (m_cursor > 0) { - if (isspace(m_buffer[(int)m_cursor - 1])) { + if (isspace(m_buffer[m_cursor - 1])) { if (has_seen_nonspace) break; } else { @@ -500,8 +502,8 @@ String LineEditor::get_line(const String& prompt) fputs(prompt.characters(), stdout); for (size_t i = 0; i < m_buffer.size(); ++i) fputc(m_buffer[i], stdout); - if (m_cursor < (size_t)m_buffer.size()) - printf("\033[%zuD", (size_t)m_buffer.size() - m_cursor); // Move cursor N steps left. + if (m_cursor < m_buffer.size()) + printf("\033[%zuD", m_buffer.size() - m_cursor); // Move cursor N steps left. fflush(stdout); continue; } @@ -521,10 +523,10 @@ String LineEditor::get_line(const String& prompt) continue; } if (ch == 0x05) { // ^E - if (m_cursor < (size_t)m_buffer.size()) { - printf("\033[%zuC", (size_t)m_buffer.size() - m_cursor); + if (m_cursor < m_buffer.size()) { + printf("\033[%zuC", m_buffer.size() - m_cursor); fflush(stdout); - m_cursor = (size_t)m_buffer.size(); + m_cursor = m_buffer.size(); } continue; } diff --git a/Userland/man.cpp b/Userland/man.cpp index 055961bd2e..47c3d7d9d9 100644 --- a/Userland/man.cpp +++ b/Userland/man.cpp @@ -97,7 +97,7 @@ int main(int argc, char* argv[]) dbg() << "Loading man page from " << file->filename(); auto buffer = file->read_all(); - String source { (const char*)buffer.data(), (size_t)buffer.size() }; + auto source = String::copy(buffer); printf("%s(%s)\t\tSerenityOS manual\n", name, section); diff --git a/Userland/md.cpp b/Userland/md.cpp index 50297ba47a..f0f5ee576e 100644 --- a/Userland/md.cpp +++ b/Userland/md.cpp @@ -68,7 +68,7 @@ int main(int argc, char* argv[]) auto buffer = file->read_all(); dbg() << "Read size " << buffer.size(); - String input { (const char*)buffer.data(), (size_t)buffer.size() }; + auto input = String::copy(buffer); MDDocument document; success = document.parse(input); |