mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
uemis: replace C-strings by std::string and std::string_view
The string code of uemis-downloader.cpp was broken in more ways than can be listed here. Notably, it brazenly refused to free any memory allocated for the parameters buffer. Using std::string and std::string_view should plug all those memory holes. That made it necessary to do some major refactoring. This was done blind and therefore will break. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
16e19b550b
commit
58b3583b3b
9 changed files with 384 additions and 403 deletions
|
|
@ -1,8 +1,10 @@
|
|||
#include "downloadfromdcthread.h"
|
||||
#include "core/errorhelper.h"
|
||||
#include "core/format.h"
|
||||
#include "core/libdivecomputer.h"
|
||||
#include "core/qthelper.h"
|
||||
#include "core/range.h"
|
||||
#include "core/uemis.h"
|
||||
#include "core/settings/qPrefDiveComputer.h"
|
||||
#include "core/divelist.h"
|
||||
#if defined(Q_OS_ANDROID)
|
||||
|
|
@ -15,16 +17,6 @@ static QHash<QString, QStringList> mobileProductList; // BT, BLE or FTDI support
|
|||
QMap<QString, dc_descriptor_t *> descriptorLookup;
|
||||
ConnectionListModel connectionListModel;
|
||||
|
||||
static QString str_error(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
const QString str = QString::vasprintf(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
static void updateRememberedDCs()
|
||||
{
|
||||
QString current = qPrefDiveComputer::vendor() + " - " + qPrefDiveComputer::product() + " - " + qPrefDiveComputer::device();
|
||||
|
|
@ -108,19 +100,20 @@ void DownloadThread::run()
|
|||
clear_divelog(&log);
|
||||
|
||||
Q_ASSERT(internalData->log != nullptr);
|
||||
const char *errorText;
|
||||
std::string errorText;
|
||||
import_thread_cancelled = false;
|
||||
error.clear();
|
||||
if (!strcmp(internalData->vendor, "Uemis"))
|
||||
errorText = do_uemis_import(internalData);
|
||||
else
|
||||
errorText = do_libdivecomputer_import(internalData);
|
||||
if (errorText) {
|
||||
error = str_error(errorText, internalData->devname, internalData->vendor, internalData->product);
|
||||
report_info("Finishing download thread: %s", qPrintable(error));
|
||||
if (!errorText.empty()) {
|
||||
error = format_string_std(errorText.c_str(), internalData->devname.c_str(),
|
||||
internalData->vendor.c_str(), internalData->product.c_str());
|
||||
report_info("Finishing download thread: %s", error.c_str());
|
||||
} else {
|
||||
if (!log.dives->nr)
|
||||
error = tr("No new dives downloaded from dive computer");
|
||||
error = tr("No new dives downloaded from dive computer").toStdString();
|
||||
report_info("Finishing download thread: %d dives downloaded", log.dives->nr);
|
||||
}
|
||||
qPrefDiveComputer::set_vendor(internalData->vendor);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue