mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:37:46 +00:00
LibLine: Fix writing to temporary file in ^X^E handler
I have no idea how this _ever_ worked, and I also have no idea why past me didn't use FileStream to begin with. Fixes the issue where lots of junk data would be written to the temp file, causing the external editor to crash.
This commit is contained in:
parent
f91bfe8009
commit
6783f65d5a
1 changed files with 8 additions and 7 deletions
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/FileStream.h>
|
||||||
#include <AK/ScopeGuard.h>
|
#include <AK/ScopeGuard.h>
|
||||||
#include <AK/ScopedValueRollback.h>
|
#include <AK/ScopedValueRollback.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
@ -527,15 +528,15 @@ void Editor::edit_in_external_editor()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OutputFileStream stream { fp };
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append(Utf32View { m_buffer.data(), m_buffer.size() });
|
builder.append(Utf32View { m_buffer.data(), m_buffer.size() });
|
||||||
auto view = builder.string_view();
|
auto bytes = builder.string_view().bytes();
|
||||||
size_t remaining_size = view.length();
|
while (!bytes.is_empty()) {
|
||||||
|
auto nwritten = stream.write(bytes);
|
||||||
while (remaining_size > 0)
|
bytes = bytes.slice(nwritten);
|
||||||
remaining_size = fwrite(view.characters_without_null_termination() - remaining_size, sizeof(char), remaining_size, fp);
|
}
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeGuard remove_temp_file_guard {
|
ScopeGuard remove_temp_file_guard {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue