This includes using the C++ version of membuffer. There appears
to not have been a leak, because the buffer is freed in
flush_buffer(), but usage was somewhat inconsistent and hard to
follow.
Also, convert some string handling to std::string to avoid free()
madness.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
get_changes_made(), subsurface_user_agent() and normalize_cloud_name()
are only called from C++.
Avoids having to manually free the returned value and is therefore
more robust against leaks.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The code is now much easier to check for memory leaks,
since there are no explicit free()s. Yes, memory is not
released immediately, but that should be of no concern.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This changes default behavior when creating a sample struct
in C++ code: it is now initialized to default values. If this
ever turns out to be a performance problem, we can either add
additional constructors or use special functions that do
not initialize memory, such as make_unique_for_overwrite.
This removes non-standard (respectively >C++20) constructs,
namely designated initializers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Avoid error-prone malloc/free pairs. This uses somewhat
obscure constructs to stay as close as possible to the
original C code. Notably, it uses mostly unique_ptr<T[]>
which doesn't store the length of the array, because the
length is supposed to be known.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Long term project: convert core to C++ so that we can
use higer-level constructs, notably std::vector<>.
This does not change any code - only fixes compile issues.
Mostly casting of (void *) to the proper type. Also designated
initialization of the sample struct had to be rearranged.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the core, we usually want C strings, not QStrings. Therefore,
make translated C strings directly available from C++.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function clear_*_table frees all elements of the table.
However, persumably as a performance feature, it kept the
memory of the table itselt (i.e. it only reset the number of
elements but kept the capacity).
That is fine if the table is reused later. However, this
function was also used when freeing the table and this
would leak the table memory.
This commit frees the table memory. An alternative would
be to have separate clear_*_table and free_*_table functions.
But let's wait with that until we port the table code to C++.
Then this will be "automatically" fixed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Firstly, why calculate something when the next statement is a return
anyway.
Secondly, the calculation subtracts two completely unrelated pointers.
This must be some code reshuffling artifact.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add support for the new dive computer models that have been added in the
latest version of libdivecomputer.
Signed-off-by: Michael Keller <mikeller@042.ch>
Currently, the "hide event" status is lost when switching dives.
Save it in the event struct instead to make it persistent.
In the future we might save this information to the log file.
Then this should be integrated in the undo-system.
This commit also makes the "unhide events" menu entry more
fine grained: It now differentiates between individual
events and event types.
Note this adds an additional field to the event structure.
There is a "deleted" field that is used internally for
book-keeping, but probably should be removed. Not touching
this at the moment as long as this is C-only code. When/if
switching to C++ we can make the event linked list a table,
which will make this much simpler.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Currently the event type code uses libdivecomputer's flags
to differentiate between events. Make this explicit and extract
the event severity.
The reason is that later we want to be more explicit about showing/
hiding events and thereto we must format the name of events.
Moreover, this encapsulates the complexities of extracting
the severity in the event code (that used to be in the profile
code).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of passing name / flag pairs to event_type functions,
pass a pointer to the event. This hides implementation details.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This structure is used to hide events of a certain type.
The type was inferred from its name, but now includes flags.
So event_type is more appropriate.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Reinstate the hiding of events by event type across
all dives in the log. This was unintentionally removed in #3948.
Also change the event type to be specific to name and severity, and fix
bug causing 'Unhide all events' to not show when only individual events
were hidden.
This still leaves the inconsistency that hiding of similar events is
persisted across the switch between dives, but hiding of individual
events is lost when switching dives, which is mildly confusing.
Follow-up to #4092.
Signed-off-by: Michael Keller <github@ike.ch>
The planner uses a one-past-end pseudo cylinder for marking the
surface interval outside of water. This overflowed arrays in
setup_gas_sensor_pressure().
See #4086. Note: contains a second unrelated crash report.
As a band-aid allocate bigger arrays. But obviously, the proper
fix is to not generate invalid gas-change events.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Fix the configuration of the deco ceilings in the mobile version:
- make the settings work;
- remove reading of the dive computer ceiling from git;
- hide the gradient factor in the profile when the calculated ceiling is
not shown;
- when the calculated ceiling is disabled in the settings, disable
editing of the gradient factor.
Signed-off-by: Michael Keller <github@ike.ch>
If the XML document could not be parsed then `root_element` will come
out as NULL. Check this before trying to dereference it.
Signed-off-by: Richard Fuchs <dfx@dfx.at>
The Divesoft Liberty has four O2 sensors. So far, we had a hard coded
limit of three sensors and crashed with a failed assert when we
encoutered more than three. This allows for up to
MAX_O2_SENSORS which is currently 6. The voting logic is adapted
accordingly: We sort the values and we keep deleting the values that
differ more than 20% by value from the closest. This follows what
Shearwater implements on their computers.
In some of the import/export functions the value is still hard
coded to 6 thanks to explicit field names.
Signed-off-by: Robert C. Helling <helling@lmu.de>
fp_get_data() returns a copy of a string that must be freed.
Fix this in save-git.c. The analogous function in save-xml.c
has already been fixed. However, change the code to be more
idiomatic: since we own the pointer, make it "char *" instead
of "const char *". Then we don't have to cast on free().
Ultimately, we really should change string manipulation code
to C++.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Mostly irrelevant std::move() stuff of copy-on-write Qt objects,
a few real bugs, a timestamp_t downconversion and some codingsyle
adaptation.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If prefs.show_icd is false, this function does nothing, but
the output parameter is checked by the calling function
DiveEventItem::setupToolTipString().
Let's reset the strucvture to 0.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When adjusting picture times, the offset in seconds is stored in a
32-bit int. Make it a 64-bit int. Sounds crazy, because why would
you want to move the pictures by more than 70 years?
Well, suppose it is the year 2039, for some strange reason your
camera was set to unix epoch and you want to adjust the pictures
to current time.
Ok - that's a far-fetched scenario. The real reason is that this
hopefully silences a Coverity warning and avoids integer casting.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Unfortunately Coverity doesn't understand that most Qt data
structures are copy-on-write. It's a mis-feature of Qt, but
it is the way it is. Thus, passing by value is not an issue.
Out of ca. 25 warnings only two were legit. Let's silence
the others by either std::move()ing or passing by reference,
as would be idiomatic C++, which Qt is not.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There are two enums related to the type of dive.
There is the global
enum divemode_t {OC, CCR, PSCR, FREEDIVE, NUM_DIVEMODE,
UNDEF_COMP_TYPE};
and the anonymous
enum {AIR, NITROX, TRIMIX, FREEDIVING} dive_type;
in struct plot_info.
In profile.c FREEDIVE (of divemode_t) is assigned to dive_type.
This only works because by chance(?) FREEDIVE and FREEDIVING are
the fourth element of each enum.
Fix this. C truly is a bad language when it comes to types
(very weak) and namespaces (non existing).
Contains whitespace fix.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This hasn't been used on the backend in a long time (and appears to get
stripped out on several platforms). No point in keeping it around.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
While the update to the copyright year really isn't required, it just looks
better.
By using the canonical instead of the git version in user visible strings we
are creating more consistency in how we refer to the version.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
- for now all versions start with v6.0
- CICD builds use the monolithic build number as patch level, e.g. v6.0.12345
- local builds use the following algorithm
- find the newest commit with a CICD build number that is included in the
working tree
- count the number of commits in the working tree since that commit
- if there are no commits since the last CICD build, the local build version
will be v6.0.12345-local
- if there are N commits since the last CICD build, it will be
v6.0.12345-N-local
- test builds in the CICD that don't create artifacts simply use a dummy release
in order to not incorrectly increment the build number and also not to waste
time and resources by manually checking out the nightly-build repo for each of
these builds.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Increase the precision of the setpoint that can be specified per planned
leg of the dive to 0.01 mbar.
Some rebreather models (APD Inspiration) support this precision for
setpoint setting.
Motivated-by: https://groups.google.com/g/subsurface-divelog/c/pD5gYlG5szI/m/G8_as4TyBwAJ
Signed-off-by: Michael Keller <github@ike.ch>
I ran into this a couple of times where the debug output didn't seem to
make any sense until I understood that libgit simply didn't give me
detailed error info.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is not a great way to load-balance, but it works and doesn't require
high end hardware on the backend.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If there are no gas mixes returned by libdivecomputer, we need to default to air. The previous commit would have defaulted to pure oxygen.
Signed-off-by: Micha WERLE <micha@michaelwerle.com>
During code review, an argument was made to use the bottom gas mix as
the mix to fill additional tanks with instead of the last mix reported
by the dive computer.
This change implements `get_deeper_gasmix` which compares two gas mixes
and returns the one with the lower MOD. This comparison does not perform
actual MOD calculations but only performs a relative oxygen and helium
content comparison.
Instead of saving the last gas mix and assigning it to additional tanks,
a `bottom_gas` mix is saved and assigned instead.
Signed-off-by: Micha WERLE <micha@michaelwerle.com>
Reverted "optimisation" based on code feedback.
Firstly, it's implementation-defined whether or not a stack frame is created for sub-scopes, secondly any optimisation is questionable regardless, and thirdly it was felt that it makes the code harder to understand.
Signed-off-by: Micha WERLE <micha@michaelwerle.com>
Instead of defaulting to air when we run out of gas mixes to assign to
cylinders, use the last gas mix provided by the dive computer.
If no gas mixes are provided at all, then default to air.
This prevents Subsurface from "inventing" gas mixes which are not
reported by the dive computer. It also works very nicely with a sidemount
configuration where the dive computer typically reports two cylinders but
only a single gas mix.
Signed-off-by: Micha WERLE <micha@michaelwerle.com>
The divecomputer_device_open() function tries all supported transports
one by one, and exits as soon as one is opened successfully. When the
end of the function is reached, the DC_STATUS_UNSUPPORTED error code is
returned.
The annoying side effect is that the actual error code returned by the
transport is ignored and changed into DC_STATUS_UNSUPPORTED. This is
very confusing while troubleshooting download problems.
Fixed by initializing the error code to DC_STATUS_UNSUPPORTED, in case
no transport is available for trying, and returning the last reported
error to caller.
Signed-off-by: Jef Driesen <jef@libdivecomputer.org>
Add the Aqualung i330R and Apeks DSX model numbers to the Pelagic
pattern table. These two models also use a new BLE service UUID.
Signed-off-by: Jef Driesen <jef@libdivecomputer.org>