From 792e13d2b2dda20e171f6f46392762b7210dd5a1 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 28 Mar 2024 08:25:16 -0700 Subject: [PATCH] Actually return NMEA string with CRLF --- src/NMEA_build.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/NMEA_build.cpp b/src/NMEA_build.cpp index 934438a..355b962 100644 --- a/src/NMEA_build.cpp +++ b/src/NMEA_build.cpp @@ -566,11 +566,12 @@ 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 size_t len = strlen(nmea); - char *newStr = + char *nmeaWithCRLF = (char *)malloc(len + 3); // +2 for \r\n, +1 for null terminator - if (newStr) { - strcpy(newStr, nmea); // Copy original string - strcat(newStr, "\r\n"); // Append \r\n + if (nmeaWithCRLF) { + strcpy(nmeaWithCRLF, nmea); // Copy original string + strcat(nmeaWithCRLF, "\r\n"); // Append \r\n + return nmeaWithCRLF; // return pointer to finished product } } return nmea; // return pointer to finished product