Attempt to fix compiler warnings 2

This commit is contained in:
Melissa LeBlanc-Williams 2024-03-27 12:54:27 -07:00
parent e8da4230f9
commit 02b1489f27
1 changed files with 5 additions and 6 deletions

View File

@ -565,12 +565,11 @@ 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
int neededSize = strlen(nmea) + 2; size_t len = strlen(nmea);
char *tempBuffer = (char *)malloc(neededSize); char *newStr = malloc(len + 3); // +2 for \r\n, +1 for null terminator
if (tempBuffer != NULL) { if (newStr) {
sprintf(tempBuffer, neededSize, "%s\r\n", nmea); strcpy(newStr, nmea); // Copy original string
strcpy(nmea, tempBuffer); strcat(newStr, "\r\n"); // Append \r\n
free(tempBuffer);
} }
} }
return nmea; // return pointer to finished product return nmea; // return pointer to finished product