From 40a3e562b01de2827fa6c2c5fd9d46631f91dc36 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 25 Mar 2019 09:05:47 +0100 Subject: Cleanup: provide printGPSCoords in C and C++ versions printGPSCoords() returned a newly allocated C-style string. Most callers simply made a QString out of it and freed the C-style string. This is paradoxical, as printGPSCoords internally works with QStrings and converts them to C-style on return. Therefore, let printGPSCoords() return a QString and create a printGPSCoordsC() wrapper for the two C-callers. Signed-off-by: Berthold Stoeger --- core/qthelper.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'core/qthelper.cpp') diff --git a/core/qthelper.cpp b/core/qthelper.cpp index 26a8a68f9..1a85d35a7 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -72,7 +72,7 @@ QString distance_string(int distanceInMeters) return str; } -extern "C" char *printGPSCoords(const location_t *location) +QString printGPSCoords(const location_t *location) { int lat = location->lat.udeg; int lon = location->lon.udeg; @@ -82,7 +82,7 @@ extern "C" char *printGPSCoords(const location_t *location) QString lath, lonh, result; if (!has_location(location)) - return strdup(""); + return QString(); if (prefs.coordinates_traditional) { lath = lat >= 0 ? gettextFromC::tr("N") : gettextFromC::tr("S"); @@ -101,7 +101,12 @@ extern "C" char *printGPSCoords(const location_t *location) } else { result.sprintf("%f %f", (double) lat / 1000000.0, (double) lon / 1000000.0); } - return copy_qstring(result); + return result; +} + +extern "C" char *printGPSCoordsC(const location_t *location) +{ + return copy_qstring(printGPSCoords(location)); } /** -- cgit v1.2.3-70-g09d2