diff --git a/src/Adafruit_GPS.cpp b/src/Adafruit_GPS.cpp index bed5c38..fd8086c 100644 --- a/src/Adafruit_GPS.cpp +++ b/src/Adafruit_GPS.cpp @@ -352,7 +352,7 @@ char Adafruit_GPS::read(void) { // Serial.print(c); currentline[lineidx] = c; - lineidx++; + lineidx = lineidx + 1; if (lineidx >= MAXLINELENGTH) lineidx = MAXLINELENGTH - 1; // ensure there is someplace to put the next received character diff --git a/src/NMEA_build.cpp b/src/NMEA_build.cpp index 832a0c6..e113e53 100644 --- a/src/NMEA_build.cpp +++ b/src/NMEA_build.cpp @@ -565,7 +565,13 @@ char *Adafruit_GPS::build(char *nmea, const char *thisSource, addChecksum(nmea); // Successful completion if (!noCRLF) { // Add Carriage Return and Line Feed to comply with NMEA-183 - sprintf(nmea, "%s\r\n", nmea); + int neededSize = strlen(nmea) + 2; + char *tempBuffer = (char *)malloc(neededSize); + if (tempBuffer != NULL) { + sprintf(tempBuffer, neededSize, "%s\r\n", nmea); + strcpy(nmea, tempBuffer); + free(tempBuffer); + } } return nmea; // return pointer to finished product }