Commit graph

1862 commits

Author SHA1 Message Date
Berthold Stoeger
4355ce3924 Cleanup: move copy_cylinder_types() from dive.c to equipment.c
Thus, future callers will not have to include the monster dive.h
include if they just want to copy cylinders.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
860807bf92 Core: create copy_cylinder_type() function
Move the loop body of copy_cylinder_types() into its own function.
When using variable sized arrays, this loop will have to treat two
cases (overwrite cylinder and add new cylinder), so that makes things
more clear.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
f2bcc240c4 Core: dynamically allocate cylinder maps in merge_cylinders()
merge_cylinders() used three bitmaps to identify cylinders used in
the first and second dive and matched cylinders. Even though nobody
will use more than 32 (or 64!) cylinders, replace these with
dynamically allocated bool-arrays for consistency with the rest
of the code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
371a5fd66b Core: dynamically allocate gases array
When calculating per-cylinder mean depths, bitfields were used to
keep track of "used" and "known" cylinders. Even though no sane
person will use more than 32 cylinders, turn this into dynamically
allocated arrays of bool for consistency with the rest of the code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
05a5a06fd3 Profile: dynamically allocate gases array
To calculate sac rates, an array of used gases for every point on the
profile was used. This was implemented using unsigned int bitfields.

While nobody sane will ever use 32 or even 64 cylinders, for consistency
with the rest of the code, also change this to use dynamically
allocated arrays.

But allocate only once per shown profile, not once per sample.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
00289cd222 Profile: dynamically allocate plot pressure data
All accesses to the pressure data were converted to use functions.
Therefore it is now rather trivial to dynamically allocate the
pressure array and just change the functions.

The only thing to take care of is the idiosyncratic memory
management. Make sure to free and copy the buffer in the
appropriate places.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
7c6a904bbf Profile: use pressure data functions in save_profiles_buffer
The save_profiles_buffer() function was accessing the pressure
data directly. Instead, use the already existing funcions to
make transition to dynamically allocated pressure data more
seamless.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
4c9532dc51 Profile: use pressure data functions in fill_missing_tank_pressures
The pressure data was directly accessed in fill_missing_tank_pressures().
Use the already existing functions so that the structures can be adapted
easily.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
7e1425796d Profile: turn INSERT_ENTRY macro into helper function
The only apparent reason that this was a macro is that it automatically
increased the "index" and "entry" counts. But incrementing these explicitly
seems reasonable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
2fd4cb5fe1 Profile: pass index instead of pointer to set_plot_pressure_data
Another plot-pressure-related function whose argument is converted
to an index.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
fe6d3c8c38 Profile: switch pressure-accessing functions to indexes
Continue with replacing pointers to struct plot_data entries
by indexes. Thus the pressure data can be kept in its own
array and can by dynamically sized.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
4724c88533 Profile: change get_plot_pressure to take index instead of pointer
The goal here is to make it possible to detach the pressure related
data from the plot_info structure. Thus, the pressure related data
can be allocated independently depending on the number of cylinders
per dive.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
16bdbc54b9 Cylinders: dynamically allocate cylinder arrays
Dynamically allocate cylinder arrays in C code. This is a tiny
step in removing the MAX_CYLINDERS limitation.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
11467fa326 Core: dynamically allocate the result of get_gas_used()
get_gas_used() returns the volume of used gases. Currently,
an array with MAX_CYLINDERS is passed in. If we want to make the
number of cylinders dynamic, the function must use an arbitrarilly
sized array.

Therefore, return a dynamically allocated array and free it
in the caller.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Dirk Hohndel
2637106309 core: reorder dive structure elements to avoid padding
Memory is cheap these days. Still, this was wasteful. On a 64 bit machine we
went from 1620 to 1592 bytes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-11-08 20:50:05 +01:00
Dirk Hohndel
ff47dd9b30 core: add collapsed state to the dive data structure
This is only used in Subsurface-mobile.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-11-08 20:50:05 +01:00
Robert C. Helling
a3a3913e1e Planner: Don't accumulate rounding errors in stop durations
When displaying segment or stop times in the planner notes, we always
round to the next full minute. This can mean for example that we
round down more often than rounding up with the result that the sum
of the segment times does not match the total runtime and can for example
lead to stops that are shown with 0min duration.

With this patch, we increase the reference time of the last display only
by the duration time actually shown. This way, the rounding errors don't
accumulate but having rounded down previously makes rounding up the next
time more propable.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-03 04:05:29 -08:00
Robert C. Helling
9c8fbe494d Planner: Add option to treat O2 as narcotic
When computing the best mix for a target depth, for helium, one
can either require that the partial pressure of N2 is the same
as at the target depth or the partial pressure of N2 plus O2.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-10-31 00:30:38 -07:00
Dirk Hohndel
fd9e1d6a8a Cleanup: avoid dereferencing NULL
We should call this function with two well defined dive_or_trip structures
which means that exactly one of the two values is set in each argument. But
in order to not have bugs elsewhere leed to crashes here, be more tolerant
of malformed argumnts.

Fixes CID 350100

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-28 05:44:33 -07:00
Dirk Hohndel
1951371bbb Cleanup: prevent NULL dereference
This should never happen based on the logic in the callers, but just
to be on the safe side.

Should fix CID 350128

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-28 05:44:33 -07:00
Dirk Hohndel
b0a00cd15d Cleanup: use helper to avoid NULL dereference
We have these helper functions for exactly this purpose.

Found by Coverity. Fixes CID 350129

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-28 05:44:33 -07:00
Linus Torvalds
a9b1fbdcc5 Don't expose 'detach_buffer()' to membuffer users
The native buffer of a membuffer is not NUL-terminated, so when you want
to detach it and use it as a C string, you had to first do
'mb_cstring()' that adds the proper termination/

This was all documented in the header files, and all but two users did
it correctly.

But there were those two users, and the exported interface was
unnecessarily hard to use.  We do want the "just detach the raw buffer"
internally in the membuffer code, but let's not make the exported
interface be that hard to use.

So this switches the exported interface to be 'detach_cstring()', which
does that 'mb_cstring()' for you, and avoids the possibility that you'd
use a non-terminated memory buffer as a C string.

The old 'detach_buffer()' is now purely the internal membuffer
implementation, and not used by others.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-10-27 12:42:54 -07:00
Dirk Hohndel
33137c62b0 Cleanup: NULL check pointer before dereferencing
Found by Coverity. CID 350081, 350087, 350095

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-27 07:35:46 -07:00
Dirk Hohndel
1c8c62ce20 Cleanup: consider lseek return value
This seems excessively unlikely to actually fail. SEEK_END works, but SEEK_SET
fails? Oh well. Belts and suspenders.

Found by Coverity. Fixes CID 45039

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-27 07:35:46 -07:00
Dirk Hohndel
ee6b89268e Cleanup: close open file before returning
This prevents a resource leak.

Found by Coverity. Fixes CID 350080

The commit also includes some tiny whitespace/empty line fixes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-27 07:35:46 -07:00
Dirk Hohndel
86b76b0aff Cleanup: pass NULL pointer for error string pointer (part 2)
I missed one file fixing this earlier.

Since we never did anything with the error string, why even ask for it.
And this way we don't have to deal with the memory returned, either.

Found by Coverity. Fixes CID 350082

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-27 07:35:46 -07:00
Dirk Hohndel
7b45b93080 Cleanup: fix obvious resource leak
Found by Coverity. Fixes CID 350084

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-26 19:17:53 -07:00
Dirk Hohndel
d3d51b175d Cleanup: pass NULL pointer for error string pointer
Since we never did anything with the error string, why even ask for it.
And this way we don't have to deal with the memory returned, either.

Found by Coverity. Fixes CIDs 350124, 350113, 350106, 350099, 350091

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-26 19:17:53 -07:00
Dirk Hohndel
cc2269b9c5 Cleanup: don't add invalid dive to trip
Even if there is a valid trip, we should not add a structure that isn't
a dive to it.

Found by Coverity. Fixes CID #350073

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-26 19:17:53 -07:00
Dirk Hohndel
30566135aa Cleanup: clean up resource handling in ostctools.c
Free resources allocated by alloc_dive() with free_dive().
Don't allocate and re-allocate a fixed two byte buffer on the heap.

Indirectly this fixes CID 216616

Suggested-by; Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-26 19:17:53 -07:00
Dirk Hohndel
0b47757f2a Cleanup: unconditionally call free
While this is debatably correct, free will happily accept (and ignore
the NULL pointer), so let's just always call it and make Coverity happy.

Fixes CID 45163

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-26 19:17:53 -07:00
Dirk Hohndel
bf6a644fc6 Mobile: provide better tracking of applied GPS fixes
Also reset the page stack to make sure we don't end up with stale data.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-26 11:38:26 -07:00
Berthold Stoeger
8dea2ada3b Undo: turn dive- and trip-fields into flags
The divesEdited signal sends the changed field as a parameter.
Since some undo-commands change multiple fields, this led to
numerous signals for a single command. This in turn would lead
to multiple profile-reloads and statistic recalculations.

Therefore, turn the enum into a bitfield. For simplicity,
provide a constructor that takes classical flags and turns
them into the bitfield. This is necessary because C-style
named initialization is only supported on C++20 onward!

Is this somewhat overengineered? Yes, maybe.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26 11:36:23 -07:00
Berthold Stoeger
6a6b992a77 Desktop: make salinity a field known to the undo system
The undo system sets updates individual dive fields on
redo respectively undo. Make salinity such a field, since
it is changed on replanning a dive.

To do this, break out the "update salinity" functionality
into its own function, add an entry to the DiveField enum
and add the corresponding switch-case.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26 11:36:23 -07:00
Berthold Stoeger
d16d57577d Core: export dive-computer freeing function
The dive-computer freeing code was local to dive.c. Implementing
the replan undo-command will need that functionality. Therefore,
export it as a global function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26 11:36:23 -07:00
Dirk Hohndel
56e8ac0bd7 Cleanup: free nickname only once
Found by Coverity. Fixes CID 350123

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-26 11:35:16 -07:00
Dirk Hohndel
394948e2cf Mares: improve BT discovery logic
At least in one of the logs we saw there seemed to be trailing spaces.
It should be enough for the BT name to start with "Mares Genius" in
order to be recognized.

Suggested-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-26 04:39:32 -07:00
Linus Torvalds
7273161acf Mares: add BT discovery logic
We don't have the "show all dive computers" logic on mobile, so we need
something like this.

Possibly we should use the libdivecomputer matching code if it exists,
but that's a much bigger change, let's do this incremental one for now.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-10-25 04:34:51 -07:00
Dirk Hohndel
32ae3810ce Core: move cylinder list getter into helper function
Thie way we can use it from the dive list model.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-20 16:08:55 -04:00
Dirk Hohndel
09c7115e21 Core: make helper functions global
We'll use them from the model in order to avoid creating this many
DiveObjectHelpers when showing a dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-20 16:08:55 -04:00
Dirk Hohndel
5a10cd42f7 Core: debug helper for DOH constructor
This is disabled by default - but when compiled in it makes it a lot
easier to pinpoint why we are creating so many DiveObjectHelpers.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-20 16:08:55 -04:00
Dirk Hohndel
d323e9381b Stop support Qt versions before 5.9
There's just no point to testing these outdated versions.
Everything we build is now Qt 5.9 or newer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-14 13:37:17 -07:00
Dirk Hohndel
9c744e401e Cloud storage: remove outdated certificate hack
The old server certificates where not recognized on some older platform,
so we hardcoded the hex digest of the valid certificate and ignored the
error.

Those certificates have been replaced last week, so there is no point to
this hack anymore - also, we should always show the SSL error, not just
in verbose mode.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-09 22:38:29 +03:00
Dirk Hohndel
4458373488 Cleanup: remove bogus code that slipped in earlier
Commit df4fbf7699 ("Android: force different font on OnePlus devices")
inadvertantly added this hunk - let's undo it again.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-05 08:19:31 -07:00
Robert C. Helling
85c31f0303 Analyze gasswitches in CCR bailout
The test if we have to create gas switches wasn't yet aware
of the bailout option.

Reported-by: Dennis Arreborg <dennis@arreborg.eu>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-10-03 08:38:19 -07:00
Dirk Hohndel
fb26f6b0fa Avoid duplicate debug output from GPS module
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-02 08:04:49 -07:00
Berthold Stoeger
087a80194a Import: keep dive and dive site tables in DiveImportedModel
The DiveImportedModel and DownloadThread used the same table
of dives and dive sites. This made it very hard to keep the
model consistent: Every modification of the download thread
would make the model inconsistent and could lead to memory
corruption owing to dangling pointers.

Therefore, keep a copy in the model. When updating the model,
use move-semantics, i.e. move the data and reset the tables
of the thread to zero elements.

Since the DiveImportedModel and the DownloadThread are very
tightly integrated, remove the accessor-functions of the
dive and dive-site tables. They fulfilled no purpose
whatsoever as they gave the same access-rights as a public
field.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02 08:04:49 -07:00
Berthold Stoeger
a353bcb296 Cleanup: make table argument to get_dive_from_table() const
Even though the returned dive is not const, the table is not
changed, as it only contains pointers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02 08:04:49 -07:00
Berthold Stoeger
a1a2492438 Cleanup: remove dive_table and dive_site_table Q_METATYPEs
These are not passed through QML anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02 08:04:49 -07:00
Berthold Stoeger
7615e71760 Import: remove QML properties from DownloadThread
QML doesn't access these directly anymore but goes via the model.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02 08:04:49 -07:00