Skip to content

Commit 1a91eb6

Browse files
authored
Merge pull request #182 from mikeysklar/combined-pr180-pr181
Fix _parseCSV() array index bug: combined PR #180 and PR #181
2 parents 7092002 + 54bf8f0 commit 1a91eb6

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit IO Arduino
2-
version=4.3.4
2+
version=4.3.5
33
author=Adafruit
44
maintainer=Adafruit <adafruitio@adafruit.com>
55
sentence=Arduino library to access Adafruit IO.

src/AdafruitIO_Data.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,21 @@ char **parse_csv(const char *line) {
823823
fQuote = 1;
824824
continue;
825825
case '\0':
826+
// Emit the final field. Previously this was dropped on the floor
827+
// because the null terminator only set fEnd and broke the loop,
828+
// so parse_csv() returned one fewer field than count_fields()
829+
// reported. Callers reading fields[n-1] would then dereference NULL.
830+
*tptr = '\0';
831+
*bptr = strdup(tmp);
832+
if (!*bptr) {
833+
for (bptr--; bptr >= buf; bptr--) {
834+
free(*bptr);
835+
}
836+
free(buf);
837+
free(tmp);
838+
return NULL;
839+
}
840+
bptr++;
826841
fEnd = 1;
827842
break;
828843
case ',':
@@ -890,12 +905,12 @@ bool AdafruitIO_Data::_parseCSV() {
890905
}
891906

892907
if (field_count > 0) {
893-
_lon = atof(fields[1]);
908+
_lon = atof(fields[2]);
894909
field_count--;
895910
}
896911

897912
if (field_count > 0) {
898-
_ele = atof(fields[1]);
913+
_ele = atof(fields[3]);
899914
field_count--;
900915
}
901916

@@ -910,6 +925,4 @@ bool AdafruitIO_Data::_parseCSV() {
910925
} else {
911926
return false;
912927
}
913-
914-
return true;
915928
}

0 commit comments

Comments
 (0)