Skip to content

Fix _parseCSV() array index bug: combined PR #180 and PR #181 - #182

Merged
brentru merged 5 commits into
adafruit:masterfrom
mikeysklar:combined-pr180-pr181
Apr 14, 2026
Merged

brentru merged 5 commits into
adafruit:masterfrom
mikeysklar:combined-pr180-pr181

Conversation

@mikeysklar

@mikeysklar mikeysklar commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Two bugs in the location CSV parsing that mask each other and together cause a crash on every received location message.

#181 — parse_csv() silently dropped the last field of every CSV string, leaving NULL in the final slot instead of the elevation value.

#180 — _parseCSV() read fields[1] three times instead of fields[1], fields[2], fields[3], so lon and ele always returned the lat value.

Tested and verified on Adafruit Feather ESP32 V2, QT Py ESP32-S3, and Feather ESP8266.

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.
In _parseCSV(), all three location fields (lat, lon, ele) were reading from fields[1], meaning lon and ele always returned the latitude value instead of their own data. Also removes an unreachable return statement at the end of the function.

@brentru brentru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikeysklar Please update library.properties with a version bump.

The updates to the code look OK. I have tested on the Feather ESP8266.

@brentru

brentru commented Apr 14, 2026

Copy link
Copy Markdown
Member

Thanks, will merge and release when tests complete

@brentru
brentru merged commit 1a91eb6 into adafruit:master Apr 14, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants