From 72686655cfaf153ea7482c679d9a9ed2257759f0 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Tue, 14 Oct 2025 22:03:41 +0100 Subject: [PATCH] Move the pv__transfer_write_completed label, jumped to on a sparse write, outside of the compound statement; and so, move all of the variables within that compound statement to the start of the function. The GCC on RHEL derivatives like AlmaLinux 9, Rocky 8, CentOS 7/6/5 throws an error if the label is at the end of that block rather than just outside it (#45). --- src/pv/transfer.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/pv/transfer.c b/src/pv/transfer.c index 2d1a953..58adc29 100644 --- a/src/pv/transfer.c +++ b/src/pv/transfer.c @@ -655,6 +655,9 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long { ssize_t nwritten; int write_errno; + bool all_nulls; + struct stat sb; + size_t write_check_position, write_end_position; if (NULL == state->transfer.transfer_buffer) { pv_error("%s", _("no transfer buffer allocated")); @@ -677,10 +680,9 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long * instead of writing the null bytes. */ if (state->control.sparse_output && !state->transfer.output_not_seekable) { - bool all_nulls = true; - size_t write_check_position, write_end_position; write_check_position = state->transfer.write_position; write_end_position = write_check_position + (size_t) (state->transfer.to_write); + all_nulls = true; while (all_nulls && write_check_position < write_end_position) { if ('\0' == state->transfer.transfer_buffer[write_check_position]) { write_check_position++; @@ -689,7 +691,6 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long } } if (all_nulls) { - struct stat sb; /* * Get the current size of the output file, @@ -789,11 +790,11 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long debug("%s", "cancelling alarm"); (void) alarm(0); #endif /* HAVE_SETITIMER */ - - pv__transfer_write_completed: - /* If lseek() worked for sparse output, it jumps down here. */ } + pv__transfer_write_completed: + /* If lseek() worked for sparse output, it jumps down here. */ + if (nwritten > 0) { bool tracking_lines = false;