Commit 590d70e
committed
Fix parse_csv() dropping the final CSV field
parse_csv() advances bptr and strdups into buf on every comma, but on
the terminating '\0' it only sets fEnd and breaks out of the loop. The
content accumulated in tmp since the last comma was never emitted, so
for an N-field CSV the function returned N-1 strings followed by NULL
even though count_fields() correctly reported N.
In practice this meant buf[N-1] was NULL. Callers like _parseCSV() that
read the last field (e.g. atof(fields[3]) for the elevation in a
value,lat,lon,ele location CSV) dereferenced NULL and crashed with
LoadProhibited on ESP32. The bug was masked on main by a second bug in
_parseCSV() that incorrectly read fields[1] three times instead of
fields[1..3], so the last slot was never actually accessed.
Fix: emit the final field from inside the '\0' case before setting
fEnd. Uses the same strdup + allocation-failure cleanup as the ','
case.1 parent 7092002 commit 590d70e
1 file changed
+15
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
823 | 823 | | |
824 | 824 | | |
825 | 825 | | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
826 | 841 | | |
827 | 842 | | |
828 | 843 | | |
| |||
0 commit comments