Commit graph

785 commits

Author SHA1 Message Date
Dirk Hohndel
6cc5b601aa Cleanup: avoid dereferencing NULL pointer
Coverity CID 208330
Coverity CID 208301

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-27 22:13:31 -08:00
Dirk Hohndel
e8719413a7 Cleanup: avoid uninitialized members
This is basically to make Coverity happy.

Coverity CID 208300

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-27 22:02:12 -08:00
Dirk Hohndel
db434702be Cleanup: avoid potentially uninitialized members
Realistically this is a false positive as we should never use a second
BTDiscovery instance - but there's nothing wrong with being extra certain.

Coverity CID 208319

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-27 17:24:12 -08:00
Dirk Hohndel
84d7d80451 Cleanup: avoid memory leak
Coverity CID 45078

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-27 17:17:31 -08:00
Dirk Hohndel
ecd8580de9 Cleanup: avoid memory leak
Coverity CID 45121
Coverity CID 45163

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-27 17:14:43 -08:00
Dirk Hohndel
d3118bedd4 Cleanup: correctly prevent memory leak
The previous attempt to fix this in commit 652e382e68 ("Cleanup: avoid a
few memory leaks") was clearly bogus. Oops.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-27 13:18:41 -08:00
Miika Turkia
43c1c0a1d1 Check different sensors on divinglog import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-12-27 20:45:24 +01:00
Dirk Hohndel
637210564a Cleanup: avoid dereferencing NULL pointer
Coverity CID 208323

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 16:33:17 -08:00
Dirk Hohndel
260ff50b0a Cleanup: avoid accessing uninitialized variable
Coverity CID 208289

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 16:12:45 -08:00
Dirk Hohndel
76cb4bc841 Cleanup: avoid out of bounds access
sizeof() is clearly the wrong way to get to the size of that array...

Coverity CID 208294

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 16:06:05 -08:00
Dirk Hohndel
04bca45552 Cleanup: avoid out of bounds access
sizeof() is clearly the wrong way to get to the size of that array...

Coverity CID 208290

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 16:06:05 -08:00
Dirk Hohndel
50571dfab3 Cleanup: avoid memory leak
Coverity CID 208298

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 15:57:45 -08:00
Dirk Hohndel
424e757094 Cleanup: avoid memory leak
Coverity CID 208308

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 15:57:44 -08:00
Dirk Hohndel
169a55d6e8 Cleanup: avoid memory leak
Coverity CID 208314

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 15:57:44 -08:00
Dirk Hohndel
2fed7a9441 Cleanup: avoid memory leak
No point in doing the strdup of the password if we then bail.

Coverity CID 208316
Coverity CID 209293

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 15:57:31 -08:00
Dirk Hohndel
f4237bf843 Cleanup: prevent out of bounds read
Don't access cylinder[MAX_CYLINDERS]

Coverity CID 208324

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 14:25:57 -08:00
Dirk Hohndel
1a46f5eb9b Cleanup: avoid memory leak
Coverity CID 208327

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 14:22:52 -08:00
Dirk Hohndel
42db44510d Cleanup: avoid memory leak
Coverity CID 208333

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 14:17:54 -08:00
Dirk Hohndel
da1d6e97f6 Cleanup: avoid memory leak
Coverity CID 208337

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 14:10:53 -08:00
Dirk Hohndel
0e94c21a55 Cleanup: prevent potential out of bounds write
Since we cannot store tanks / gases past MAX_CYLINDERS (currently 20),
there is no point in analyzing those data.

Coverity CID 208339

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 14:04:10 -08:00
Dirk Hohndel
efb2640fc7 Cleanup: avoid memory leak
The JUMP macro includes a 'goto bail', so we need to free devdata there

Coverity CID 208340

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 13:49:49 -08:00
Dirk Hohndel
652e382e68 Cleanup: avoid a few memory leaks
Coverity CID 215199
Coverity CID 215195
Coverity CID 215196
Coverity CID 215198

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 13:41:58 -08:00
Jan Mulder
37e98a8d89 Use correct date format
A very very trival fix, for a mysterious issue. When loading
GPS fix data from the server, the string date was parsed with
the format "yyy-M-d". And no, the "yyy" is no typo here, but
was the reason that data from the read from server got a
1/1/1970 data. And when a user decided to upload that data
to the server again, we ended up with 2 copies of the
GPS fix. One with correct data (as originally saved), and
one new with the bogus date.

In order to het rid of those weird 1/1/1970 GPS fixes, users
will have to remove them by hand.

Fixes: #567

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-25 19:47:57 +01:00
Robert C. Helling
ca38644005 Prevent overflow in effective GF calculation
For deep dives with long deco, the sum of deco stops could
overflow. This is prevent by turning it into long.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-25 19:47:45 +01:00
Berthold Stoeger
130f109442 Remove superfluous QScopedPointer<>s in singletons
There was a curious pattern of singletons being implemented based on
QScopedPointer<>s. This is an unnecessary level of indirection:
The lifetime of the smart pointer is the same as that of the
pointed-to object. Therefore, replace these pointers by the respective
objects.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-24 11:04:10 -08:00
Berthold Stoeger
734bd6d459 Re-add newlines to help message
The two final newlines in the help message were removed in commit
0c74f7a2c8.
Re-add them.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-24 08:28:26 -08:00
Stefan Fuchs
337f82c876 Code cleanup: Indentation mistake plus simplification
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-24 00:01:39 +01:00
Stefan Fuchs
3ad398e3a7 Remove obsolete declaration of void gfLowAtMaxDepthChanged
in ./core/subsurface-qt/SettingsObjectWrapper.h

Code for this was removed here: 5b080bedde

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-24 00:01:39 +01:00
Jan Mulder
e4530cd5ef cleanup: remove empty function
subsurface_OS_pref_setup() is not not used. Remove it.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-21 15:11:15 +01:00
Berthold Stoeger
28ae35e7df Make QMap<> access in deleteGpsFix() more idiomatic
To access a QMap<> entry, the value() function is used with a sentinel
as default value. If the sentinel is returned, the code assumes that
the searched for entry doesn't exist.

Make this code more idiomatic by using an iterator and testing for
end().

This fixes a compiler warning, because only one of the elements of
the sentinel was initialized, but the remaining elements were
copied. Harmless, because the code would exit early if it found
the sentinel. Still not nice.

While redoing this function, the entry-not-found message was improved
(adding of function name, space between massage and timestamp) and
elevated from debug to warning level.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-21 00:04:30 +01:00
Berthold Stoeger
22dc7b84f0 Handle plot_info->nr <= 0 gracefully
plot_info->nr should always be > 0. If this is not the case, write a
message to stderr instead of crashing in add_plot_pressure(). This
silences an use-of-uninitialized-variable warning.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-21 00:04:30 +01:00
Berthold Stoeger
0b2d22494c Fix use of uninitialized variable in core/profile.c
last_ceiling was used before initialization in the first iteration
of the loop in calculate_deco_information().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-21 00:04:30 +01:00
Berthold Stoeger
3c346bb341 Check return of fread() in core/ostctools.c
Since the corresponding error message appears thrice, it is translated
once at the beginning of the function (even in the non-error case).

A single-byte fread() was transformed into getc().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-21 00:04:30 +01:00
Jan Mulder
1fee77487b core: ignore erroneous quotes as well
A small redo of 78bafe8f62. The quotes cause the original
functionality not to work. Ignore them as well.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-20 15:39:54 +01:00
Jan Mulder
6e411cc67d core: fix commit 46004c39e2 for real (erroneous quotes)
Unfortunately, in my commit 48d9c8eb6e, I fixed only half of
the problems related to the functionality introduced by Stefan in
commit 46004c39e2. The lonely m (that was fixed) caused
a parsing error, but forgotten where the single quotes around
the depth value. These quotes simply causes the new functionality
not to work. Again, the fix is simple: do not erroneously save
quotes. And as the new functionality is pretty obscure
(replanning a non-planned dive, and manually entering a gas switch
depth), another bug that could go unnoticed for years.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-20 15:39:54 +01:00
Jan Mulder
8c77c15dd8 git storage: invalidate cache on merge dive site
In hindsight a very simple bug to fix, but it requires some
knowledge on the inner workings of our git storage. The changes
on merge of dive sites were simply not saved (completely) because
the git storage code has a cache that we need to invalidate
selectively (ie. for the dive we just gave a new dive site uuid)
to get things finally embedded in the overall commit.

The main reason this bug went unnoticed for more than 2 years is
that most people use the XML/SSRF format (where this problem is
non exsistent), and dive site merging is probably not a very
much used feature either.

Fixes: #939

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-19 05:13:23 -08:00
Jan Mulder
78bafe8f62 core: ignore bogus m in cylinder
A bogus key/value pair was introduced in the cylinder,
consisting of a lonely "m" without value. This is caused
by commit 46004c39e2 and fixed in 48d9c8eb6e. See referenced
commits for more info.

Just ignore this key/value pair. No processing is broken
due to this, as the git storage stores only metric SI type data.
In fact, the m unit is superfluous anyway.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-18 21:00:01 +01:00
Robert C. Helling
3985a8aa8f Allow to read factor cache concurrently
In a session with the profile I saw that the planner spends
a lot of time waiting to obtain the lock for the factor cache.
Most of the time we are only reading that cache and that
is save to do in parallel (according to the Qt IRC channel).

So we can use a QReadWriteLock instead of a QMutex. This
appears to be quite a performance boost, in particular
for VPM-B

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-18 11:29:17 -08:00
Berthold Stoeger
7b88f8301e Elevate "can't write hashes" message from debug to warning level
I never realized that my hashes weren't written, because it only
outputs a debug instead of a warning message.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-18 15:23:12 +01:00
Jan Mulder
48d9c8eb6e core: fix git storage save (regression 4.7.4 -> 4.7.5)
Commit 46004c39e2 introduces a new field in the logbook outputs
(depth of a cylinder). While in XML the depth unit is stored with a space
between value and unit (m), in our git storage, the unit m is without
space. As the git storage parser uses a space to separate individual
key/value pairs, the erroneously saved space results in parsing warnings
when opening the logbook.

The unwanted space is normally saved just after download of a new dive
from the dive computers, so all desktop-git-storage uses are affected,
and more worrying, mobile beta users.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-18 15:22:50 +01:00
Dirk Hohndel
edf569ee6c CLeanup: remove duplicate typedef
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-17 10:25:30 -08:00
Dirk Hohndel
6b80b41c7c Cleanup: durations are now signed
Somehow a whitespace fix snuck in here. Oops.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-17 10:25:01 -08:00
Berthold Stoeger
a748e7f239 Unify float calulations: use double
Internal floating point (FP) calculations should be performed using double
unless there is a very good reason. This avoids headaches with conversions.
Indeed, the vast majority of FP calculations were already done using double.
This patch adapts most remaining calculations. Not converted where things
that were based on binary representations and variables which weren't used
anyway.

An analysis of all instances follows:

core/plannernotes.c, l.404:

This was a comparison between two floats. On the left side, first an integer
was cast to float then multiplied with and integer and divided by a constant
double. The right hand side was an integer cast to a float. Simply divide by
1000.0 first to convert to double and continue with calculations. On the right
hand side, remove the cast, because the integer will be implicitely cast to
double for comparison. This conversion actually emits less instructions,
because no conversion to double and back is performed.

core/planner.c, l.613:

Same analysis as previous case.

subsurface-desktop-main.cpp, l.155:

A local variable representing the version OpenGL version. Turn this into
integer logic. Not only does this avoid dreaded FP rounding issues, it also
works correctly for minor version > 10 (not that such a thing is to be
expected anytime soon).

abstractpreferenceswidget.[h/cpp]:

A widget where the position is described as a float. Turn into double.

desktop-widgets/divelogexportdialog.cpp, l.313:

total_weight is described as float. Use double arithmetics instead. This
instance fixes a truncation warning emitted by gcc.
2017-12-17 09:02:44 -08:00
Berthold Stoeger
074ddc0596 Remove function isCloudUrl()
The function isCloudUrl() was only called in one place, parse_file().
But, isCloudUrl() could only return true if the filename was of the
git-repository kind (url[branch]). In such a case, control flow would
never reach the point where isCloudUrl() is called, since
is_git_repository() returns non-NULL and the function returns early.

Therefore, remove this function. Moreover, adapt the affected if-statement
by replacing "str && !strcmp(str, ...)" with the more concise
"same_string(str, ...)".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-14 17:01:05 +01:00
Stefan Fuchs
82170579ad Enable removal of pictures from different dives at the same moment
Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-13 05:48:20 -08:00
Jan Mulder
3479c9e197 applying gps fixes: group repetitive code under a macro
See 2182167b53. Keep the dupicated code in sync.

Originally-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-13 05:07:15 -08:00
Jan Mulder
ee9531f76e Do not prefer gps fixes just for being into dive time
See commit 6f42ab46da. Unfortunately, this code is duplicated
(and an obvious candidate for code cleanup). So replicate the mentioned
commit here. In fact, the mentioned issue #666 talkes about the mobile
app, and the fix was only done for the desktop.

Originally-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-13 05:07:15 -08:00
Jan Mulder
9d2c52f692 Add pSCR divemode detection
In libdivecomputer, a new divemode is added (DC_DIVEMODE_SCR) useful
for dive computers that have specfic functionality for semi-closed
rebreathers. At this moment, only the HW computers seem to provide
this.

This commit takes care of proper recognition of this new divemode
when importing data from a dive computer.

Tested on an actual import from an OSTC3 that contained
dives in this new mode.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-13 05:03:36 -08:00
Jan Mulder
78d1a3ed58 Rename DC_DIVEMODE_CC to DC_DIVEMODE_CCR
This is just code cleanup. Jef renamed the CCR divemode constant
in libdivecomputer, but added a define to be backward compatible as
as well (so this rename did not break our Subsurface build).

Obviously, this breaks the build for people that build against an older
libdivecomputer, but I see no reason to do that.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-13 05:03:36 -08:00
Dirk Hohndel
c12e14a61d Update to the latest libdc version
This gets us the first merge with the upstream iostream implementation.
This requires a small change for serial_ftdi.c to build.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-12 21:16:19 -08:00