From ef1d62f215d9c390369b2807a64aa727ad2c12c9 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Sat, 21 Sep 2024 13:48:15 +0100 Subject: [PATCH] Avoid a bug when saving an empty capture. --- src/ui.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index 5b1cf524..e2624e4b 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1123,12 +1123,14 @@ where let packet_count = capture.packet_index.len(); let meta = capture.shared.metadata.load_full(); let mut saver = Saver::new(dest, meta)?; - for (result, i) in capture.timestamped_packets()?.zip(0..packet_count) { - let (timestamp_ns, packet) = result?; - saver.add_packet(&packet, timestamp_ns)?; - CURRENT.store(i + 1, Ordering::Relaxed); - if STOP.load(Ordering::Relaxed) { - break; + if packet_count > 0 { + for (result, i) in capture.timestamped_packets()?.zip(0..packet_count) { + let (timestamp_ns, packet) = result?; + saver.add_packet(&packet, timestamp_ns)?; + CURRENT.store(i + 1, Ordering::Relaxed); + if STOP.load(Ordering::Relaxed) { + break; + } } } saver.close()