This commit is contained in:
Melissa LeBlanc-Williams 2024-03-27 12:30:03 -07:00
commit cd7138fb2e
2 changed files with 8 additions and 2 deletions

View File

@ -352,7 +352,7 @@ char Adafruit_GPS::read(void) {
// Serial.print(c); // Serial.print(c);
currentline[lineidx] = c; currentline[lineidx] = c;
lineidx++; lineidx = lineidx + 1;
if (lineidx >= MAXLINELENGTH) if (lineidx >= MAXLINELENGTH)
lineidx = MAXLINELENGTH - lineidx = MAXLINELENGTH -
1; // ensure there is someplace to put the next received character 1; // ensure there is someplace to put the next received character

View File

@ -565,7 +565,13 @@ char *Adafruit_GPS::build(char *nmea, const char *thisSource,
addChecksum(nmea); // Successful completion addChecksum(nmea); // Successful completion
if (!noCRLF) { // Add Carriage Return and Line Feed to comply with NMEA-183 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 return nmea; // return pointer to finished product
} }