mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-19 03:33:43 +03:00
csplit: pacify GCC 13
* src/csplit.c (load_buffer): Refactor for clarity. This also xpacifies gcc -Wanalyzer-use-of-uninitialized-value. When reallocating the buffer, grow it by a factor of 1.5, not 2.
This commit is contained in:
1 parent
941027eeb7
commit
d178b49754
1 file changed
+15
-26
+15
-26
@@ -451,32 +451,25 @@ save_buffer (struct buffer_record *buf)
|
||||
static bool
|
||||
load_buffer (void)
|
||||
{
|
||||
struct buffer_record *b;
|
||||
idx_t bytes_wanted = START_SIZE; /* Minimum buffer size. */
|
||||
idx_t bytes_avail; /* Size of new buffer created. */
|
||||
idx_t lines_found; /* Number of lines in this new buffer. */
|
||||
char *p; /* Place to load into buffer. */
|
||||
|
||||
if (have_read_eof)
|
||||
return false;
|
||||
|
||||
/* We must make the buffer at least as large as the amount of data
|
||||
in the partial line left over from the last call,
|
||||
plus room for a sentinel '\n'. */
|
||||
if (bytes_wanted <= hold_count)
|
||||
bytes_wanted = hold_count + 1;
|
||||
idx_t bytes_wanted = MAX (START_SIZE, hold_count + 1);
|
||||
|
||||
while (true)
|
||||
{
|
||||
b = get_new_buffer (bytes_wanted);
|
||||
bytes_avail = b->bytes_alloc; /* Size of buffer returned. */
|
||||
p = b->buffer;
|
||||
struct buffer_record *b = get_new_buffer (bytes_wanted);
|
||||
idx_t bytes_alloc = b->bytes_alloc;
|
||||
idx_t bytes_avail = bytes_alloc;
|
||||
char *p = b->buffer;
|
||||
|
||||
/* First check the 'holding' area for a partial line. */
|
||||
if (hold_count)
|
||||
{
|
||||
memcpy (p, hold_area, hold_count);
|
||||
p += hold_count;
|
||||
p = mempcpy (p, hold_area, hold_count);
|
||||
b->bytes_used += hold_count;
|
||||
bytes_avail -= hold_count;
|
||||
hold_count = 0;
|
||||
@@ -484,22 +477,18 @@ load_buffer (void)
|
||||
|
||||
b->bytes_used += read_input (p, bytes_avail - 1);
|
||||
|
||||
lines_found = record_line_starts (b);
|
||||
if (record_line_starts (b) != 0)
|
||||
{
|
||||
save_buffer (b);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lines_found || have_read_eof)
|
||||
break;
|
||||
|
||||
if (INT_MULTIPLY_WRAPV (b->bytes_alloc, 2, &bytes_wanted))
|
||||
xalloc_die ();
|
||||
free_buffer (b);
|
||||
if (have_read_eof)
|
||||
return false;
|
||||
if (INT_ADD_WRAPV (bytes_alloc, bytes_alloc >> 1, &bytes_wanted))
|
||||
xalloc_die ();
|
||||
}
|
||||
|
||||
if (lines_found)
|
||||
save_buffer (b);
|
||||
else
|
||||
free_buffer (b);
|
||||
|
||||
return lines_found != 0;
|
||||
}
|
||||
|
||||
/* Return the line number of the first line that has not yet been retrieved. */
|
||||
|
||||
Reference in new issue
Block a user