ae299d5e66 introduced a format-
string bug by splitting a format-string in two and splitting
the arguments at the wrong place.
The compiler doesn't warn in this case, because the format-
string is passed through translate(...).
This should have crashed, but for some reason didn't, at least
on Linux.
Fix the arguments.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add logging of the libdivecomputer return code for errors. Also, switch
logging of errors in the background thread to callback based logging to
make it visible.
Signed-off-by: Michael Keller <github@ike.ch>
Fix the filters for planned (i.e. has at least one dive plan attached)
and logged (i.e. has at least one dive computer log attached) dives.
Also refactor the respective functions for improved readability.
Signed-off-by: Michael Keller <github@ike.ch>
Fix some findings in a Coverity scan in `core/planner.cpp` and
`core/profile.cpp`, that were reported as new after the changes
in #4126 (likely because of the rename from .c to .cpp).
Results: https://scan4.scan.coverity.com/#/project-view/60459/13160
Signed-off-by: Michael Keller <mikeller@042.ch>
Allows us to remove the strndup.h header. This code will be
even more simple, once core is fully converted away from C-strings.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The old code was leaking memory. Use std::unique_ptr<> for
ownership management.
This is still very primitive and divetags are kept during
application lifetime. There should probably be some form
of reference counting. And the taglist should not be global,
but attached to the divelog.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The only case left is in android.cpp, though that is only compiled
when compiling the full desktop app on Android. I.e. never. So
don't bother for now.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Let's use std::string in the core. Notably, I'd like to make
the numerous main() functions mostly independent of Qt. Some
things will have to remain, such as argument parsing, of course.
This changes the API: instead of returning an error code and
taking a pointer to the actual return-value, return an
std::optional<std::string>> that is set if the function succeeds.
Returning an empty string in the error case might be simpler,
but oh well...
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Use the C++-version of membuffer.
This fixes two memory leaks: report_info() on every(!) invocation
and report_error() before the error callback is set.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In C++ files, replace MIN and MAX by std::min and std::max,
respectively. There are still a few C files using these
macros. Convert them in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Had to rewrite the thing, because gcc's warnings don't work
with templatized var-args. Since there is no string-format.cpp
and I didn't want to inline it, moved it to format.cpp.
String formatting is distributed around at least four
headers: membuffer.h, subsurface-string.h, format.h
and format-string.h. This really should be unified!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Quite a bit of fallout in users of this structure.
Conveniently, since git-access.cpp is now C++ we can move
some helpers from the monstrous qthelper.cpp to git-access.cpp.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This may appear a bit ominous, as it doesn't generate a string,
but a vector of strings (one for each line). However, that is
in preparation for the QtQuickification of the profile, where
the text-items take such a list.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since this is the only caller, onvert the get_file_name() function
to return an std::string.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This used to have multiple values, but is currently only checked for
true/false. Reflect that in the type.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The deco timestep is a parameter to the plan() function. There
seems no need to define this as a global macro. Probably some
code reshuffeling artifact.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We had locale aware formatting functions that generated QStrings.
Create an alternative that creates std::string, since we want that
in the core.
This commit is unfortunate for two reasons:
- The function is called "casprintf()" for analogy with the QString
version. However, the non locale aware function is called
"format_string_std()" for analogy with "format_string()".
Ultimately these names should be unified. Probably, once there
are no membuffer users left.
- This does UTF-16->UTF-8->UTF-16 roundtrips. The core formatting
functions should render UTF-8 and only convert to UTF-16, in
the UI layer.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The combo-boxes (cylinder type, weightsystem, etc.) were controlled
by global models. Keeping these models up-to-date was very combersome
and buggy.
Create a new model everytime a combobox is opened. Ultimately it
might even be better to create a copy of the strings and switch
to simple QStringListModel. Set data in the core directly and
don't do this via the models.
The result is much simpler and easier to handle.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Remove the options to expand entities and so continue when encountering invalid /
malformed XML, as both of these can be exploited by supplying
maliciously crafted XML.
Signed-off-by: Michael Keller <mikeller@042.ch>
Q_FOREACH and foreach are anachronisms.
Range based for may cause a performance regression: it can
lead to a copy of shared containers (one reason why Qt's
COW containers are broken). However, as long as there is no
user noticeable delay, there is no point in analyzing each case.
And also no point in slapping an 'asConst' on every container
that is looped over.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To avoid memory management woes. These shouldn't be global
variables, but let's fix that later.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The memory managements for DeviceDetails was very sketchy.
First of all, sharing a pointer to a structure between threads
seems like a recipe for disaster. Secondly, the structure was
a QObject and when first generated included in the (silly)
Qt object tree, but when generated in the threads it was not.
Clearly, this leaks.
Instead, use value semantics and use local copies of the
structure. I didn't go full length and use std::move to
move the data, because this doesn't work through signals
(which are the wrong abstraction here, but OK) and secondly
I didn't have time to analyze whether the caller still
needs the data after passing it down to the worker thread.
To be able to pass an object through signals, the class
has to be registered in the Qt MetaType system. Super
ugly, but fine for now. Ultimately, this whole thing should
probably be replaced by futures, co-routines, or whatever.
Moreover, this removes the prefix from number of "m_*"
function parameters. By convention, "m_" marks member
variables, which function parameters are not.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
make DeviceDetails a metatype
So that we can pass it as value through the signal/slot system.
(squash with original commit)
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Downloder builds pull in show_computer_list() from
downloadfromdcthread.cpp, but it's declared as extern "C". With 76c2069f
having converted subsurfacestartup.c to .cpp, we can remove the extern
"C"
Signed-off-by: Richard Fuchs <dfx@dfx.at>
Add 'Country' to the fields that are indexed for fulltext search - this
seems to be a quite intuitive choice as 'Country' is also a field that
is available in the dive list view.
Fixes#4134.
Signed-off-by: Michael Keller <mikeller@042.ch>
Opportunistically fix some problems newly raised by a recent Coverity
scan.
Not touching any of the string memory allocation issues as this is being
handled by the move towards C++ strings.
Signed-off-by: Michael Keller <mikeller@042.ch>