Skip to content

Commit 8a25421

Browse files
committed
lazycsv: Treat a row with smaller columns as a parsing error
1 parent 59216ba commit 8a25421

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

crates/lazycsv/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,17 +411,18 @@ impl<'a, const COLS: usize> Iterator for CsvRowIter<'a, COLS> {
411411
let mut arr = [const { MaybeUninit::uninit() }; COLS];
412412
for i in 0..COLS {
413413
match self.csv.next() {
414+
// If we reach EOF before reading any cells, there are no more rows available.
415+
None if i == 0 => return None,
414416
Some(CsvIterItem::Cell(cell)) => {
415417
// SAFETY: we have to initialize the cell beforehand
416418
unsafe { arr.get_unchecked_mut(i).write(cell) };
417419
}
418-
Some(CsvIterItem::LineEnd) => {
420+
None | Some(CsvIterItem::LineEnd) => {
419421
return Some(Err(RowIterError::ColumnCountSmallerThanExpected {
420422
expected: COLS,
421-
actual: i - 1,
423+
actual: i,
422424
}));
423425
}
424-
None => return None,
425426
}
426427
}
427428

0 commit comments

Comments
 (0)