mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +00:00
LibLine: Fix Shell crashing (due to write() EFAULT) on <tab><tab>
Use a StringBuilder instead of blindly passing a bunch of potentially empty/null strings to the kernel. StringBuilder is more lenient and generally more pleasant to use anyway.
This commit is contained in:
parent
9ba9bba529
commit
296f87fa7f
Notes:
sideshowbarker
2024-07-19 08:01:17 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/296f87fa7fb
1 changed files with 9 additions and 11 deletions
|
@ -25,10 +25,10 @@
|
|||
*/
|
||||
|
||||
#include "Editor.h"
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace Line {
|
||||
|
@ -323,16 +323,14 @@ String Editor::get_line(const String& prompt)
|
|||
num_printed += fprintf(stderr, "%-*s", static_cast<int>(longest_suggestion_length) + 2, suggestion.characters());
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
struct iovec iov[] = {
|
||||
{ const_cast<char*>(prompt.characters()), prompt.length() },
|
||||
{ m_buffer.data(), m_cursor },
|
||||
{ m_buffer.data() + m_cursor, m_buffer.size() - m_cursor }
|
||||
};
|
||||
if (writev(STDOUT_FILENO, iov, 3)) {
|
||||
perror("writev");
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
StringBuilder builder;
|
||||
builder.append('\n');
|
||||
builder.append(prompt);
|
||||
builder.append(m_buffer.data(), m_cursor);
|
||||
builder.append(m_buffer.data() + m_cursor, m_buffer.size() - m_cursor);
|
||||
fputs(builder.to_string().characters(), stdout);
|
||||
fflush(stdout);
|
||||
|
||||
m_cursor = m_buffer.size();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue