[ansi] missed resizing a buffer when scrubbing ansi

Fixes #1135
This commit is contained in:
Tim Stack 2023-03-30 22:06:19 -07:00
parent 5ad75f156a
commit db1fc92fdd
8 changed files with 43 additions and 10 deletions

View File

@ -610,7 +610,7 @@ logfile::rebuild_index(nonstd::optional<ui_clock::time_point> deadline)
auto tmp_line = sbr.to_string_fragment().to_string();
scrub_ansi_string(tmp_line, nullptr);
memcpy(sbr.get_writable_data(),
memcpy(sbr.get_writable_data(tmp_line.length()),
tmp_line.c_str(),
tmp_line.length());
sbr.narrow(0, tmp_line.length());

View File

@ -112,16 +112,18 @@ shared_buffer_ref::shared_buffer_ref(shared_buffer_ref&& other) noexcept
}
bool
shared_buffer_ref::take_ownership()
shared_buffer_ref::take_ownership(size_t length)
{
if (this->sb_owner != nullptr && this->sb_data != nullptr) {
char* new_data;
if ((new_data = (char*) malloc(this->sb_length)) == nullptr) {
if ((this->sb_owner != nullptr && this->sb_data != nullptr)
|| this->sb_length != length)
{
auto* new_data = (char*) malloc(length);
if (new_data == nullptr) {
return false;
}
memcpy(new_data, this->sb_data, this->sb_length);
memcpy(new_data, this->sb_data, std::min(length, this->sb_length));
this->sb_length = length;
this->sb_data = new_data;
this->sb_owner->sb_refs.erase(find(this->sb_owner->sb_refs.begin(),
this->sb_owner->sb_refs.end(),

View File

@ -112,15 +112,20 @@ public:
file_range::metadata& get_metadata() { return this->sb_metadata; }
char* get_writable_data()
char* get_writable_data(size_t length)
{
if (this->take_ownership()) {
if (this->take_ownership(length)) {
return const_cast<char*>(this->sb_data);
}
return nullptr;
}
char* get_writable_data()
{
return this->get_writable_data(this->sb_length);
}
string_fragment to_string_fragment(off_t offset, size_t len) const
{
return string_fragment{
@ -151,7 +156,9 @@ public:
void erase_ansi();
bool take_ownership();
bool take_ownership(size_t length);
bool take_ownership() { return this->take_ownership(this->sb_length); }
void disown();

View File

@ -354,6 +354,7 @@ dist_noinst_DATA = \
mvwattrline_output.0 \
textfile_0.md \
textfile_ansi.0 \
textfile_ansi_expanding.0 \
textfile_json_indented.0 \
textfile_json_one_line.0 \
textfile_quoted_json.0 \

View File

@ -0,0 +1,10 @@
 * Package: sys-libs/glibc-2.36-r7:2.2
 * Repository: gentoo
 * Maintainer: toolchain@gentoo.org
 * USE: abi_x86_64 amd64 caps elibc_glibc kernel_linux multiarch ssp static-libs test userland_GNU
 * FEATURES: network-sandbox preserve-libs sandbox test userpriv usersandbox
* Checking whether python3_11 is suitable ...
* >=dev-lang/python-3.11.1-r1:3.11 ...
[ ok ]
* Using python3.11 to build (via PYTHON_COMPAT iteration)
>>> Unpacking source...

View File

@ -31,3 +31,6 @@ run_cap_test ${lnav_test} -n \
run_cap_test ${lnav_test} -n \
-c ';SELECT * FROM lnav_file_metadata' \
${test_dir}/textfile_0.md
run_cap_test ${lnav_test} -n \
${test_dir}/textfile_ansi_expanding.0

View File

@ -0,0 +1,10 @@
 * Package: sys-libs/glibc-2.36-r7:2.2
 * Repository: gentoo
 * Maintainer: toolchain@gentoo.org
 * USE: abi_x86_64 amd64 caps elibc_glibc kernel_linux multiarch ssp static-libs test userland_GNU
 * FEATURES: network-sandbox preserve-libs sandbox test userpriv usersandbox
* Checking whether python3_11 is suitable ...
* >=dev-lang/python-3.11.1-r1:3.11 ...
 [ ok ]
* Using python3.11 to build (via PYTHON_COMPAT iteration)
>>> Unpacking source...