diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index d665b0a7..dd8aa9fa 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -523,6 +523,13 @@ int tx_callback(hackrf_transfer* transfer) } else { /* Read samples from file. */ bytes_read = fread(transfer->buffer, 1, bytes_to_read, file); + + /* If no more bytes, error or file empty, treat as end. */ + if (bytes_read == 0) { + completed_byte_count += transfer->valid_length; + tx_complete = true; + return 0; + } } /* Accumulate power (magnitude squared). */ @@ -569,6 +576,12 @@ int tx_callback(hackrf_transfer* transfer) bytes_to_read - bytes_read, file); + /* If no more bytes, error or file empty, use what we have. */ + if (extra_bytes_read == 0) { + tx_complete = true; + return 0; + } + /* Accumulate power for the additional samples. */ sum = 0; for (i = 0; i < extra_bytes_read; i++) {