mirror of
https://github.com/tstack/lnav
synced 2024-11-03 23:15:38 +00:00
[line_buffer] if the size of the file is known, reduce the requested buffer size and ignore attempts to shrink the buffer
This commit is contained in:
parent
fe6781d3e8
commit
88a192aeeb
@ -222,23 +222,24 @@ throw (error)
|
||||
void line_buffer::resize_buffer(size_t new_max)
|
||||
throw (error)
|
||||
{
|
||||
char *tmp, *old;
|
||||
|
||||
require(this->lb_bz_file || this->lb_gz_file ||
|
||||
new_max <= MAX_LINE_BUFFER_SIZE);
|
||||
|
||||
/* Still need more space, try a realloc. */
|
||||
old = this->lb_buffer.release();
|
||||
this->lb_share_manager.invalidate_refs();
|
||||
tmp = (char *)realloc(old, new_max);
|
||||
if (tmp != NULL) {
|
||||
this->lb_buffer = tmp;
|
||||
this->lb_buffer_max = new_max;
|
||||
}
|
||||
else {
|
||||
this->lb_buffer = old;
|
||||
if (new_max > this->lb_buffer_max) {
|
||||
char *tmp, *old;
|
||||
|
||||
throw error(ENOMEM);
|
||||
/* Still need more space, try a realloc. */
|
||||
old = this->lb_buffer.release();
|
||||
this->lb_share_manager.invalidate_refs();
|
||||
tmp = (char *) realloc(old, new_max);
|
||||
if (tmp != NULL) {
|
||||
this->lb_buffer = tmp;
|
||||
this->lb_buffer_max = new_max;
|
||||
} else {
|
||||
this->lb_buffer = old;
|
||||
|
||||
throw error(ENOMEM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,6 +250,12 @@ throw (error)
|
||||
|
||||
require(max_length <= MAX_LINE_BUFFER_SIZE);
|
||||
|
||||
if (this->lb_file_size != -1) {
|
||||
if (start + max_length > this->lb_file_size) {
|
||||
max_length = (this->lb_file_size - start);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to see if the start is inside the cached range or immediately
|
||||
* after.
|
||||
|
@ -230,6 +230,7 @@ private:
|
||||
char *retval;
|
||||
|
||||
require(buffer_offset >= 0);
|
||||
require(this->lb_buffer_size >= buffer_offset);
|
||||
|
||||
retval = &this->lb_buffer[buffer_offset];
|
||||
avail_out = this->lb_buffer_size - buffer_offset;
|
||||
|
Loading…
Reference in New Issue
Block a user