summaryrefslogtreecommitdiffstats
path: root/core
AgeCommit message (Collapse)Author
2019-10-28Cleanup: avoid dereferencing NULLGravatar Dirk Hohndel
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-28Cleanup: prevent NULL dereferenceGravatar Dirk Hohndel
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-28Cleanup: use helper to avoid NULL dereferenceGravatar Dirk Hohndel
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-27Don't expose 'detach_buffer()' to membuffer usersGravatar Linus Torvalds
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-27Cleanup: NULL check pointer before dereferencingGravatar Dirk Hohndel
Found by Coverity. CID 350081, 350087, 350095 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-27Cleanup: consider lseek return valueGravatar Dirk Hohndel
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-27Cleanup: close open file before returningGravatar Dirk Hohndel
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-27Cleanup: pass NULL pointer for error string pointer (part 2)Gravatar Dirk Hohndel
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-26Cleanup: fix obvious resource leakGravatar Dirk Hohndel
Found by Coverity. Fixes CID 350084 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-26Cleanup: pass NULL pointer for error string pointerGravatar Dirk Hohndel
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-26Cleanup: don't add invalid dive to tripGravatar Dirk Hohndel
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-26Cleanup: clean up resource handling in ostctools.cGravatar Dirk Hohndel
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-26Cleanup: unconditionally call freeGravatar Dirk Hohndel
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-26Mobile: provide better tracking of applied GPS fixesGravatar Dirk Hohndel
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-26Undo: turn dive- and trip-fields into flagsGravatar Berthold Stoeger
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-26Desktop: make salinity a field known to the undo systemGravatar Berthold Stoeger
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-26Core: export dive-computer freeing functionGravatar Berthold Stoeger
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-26Cleanup: free nickname only onceGravatar Dirk Hohndel
Found by Coverity. Fixes CID 350123 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-26Mares: improve BT discovery logicGravatar Dirk Hohndel
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-25Mares: add BT discovery logicGravatar Linus Torvalds
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-20Core: move cylinder list getter into helper functionGravatar Dirk Hohndel
Thie way we can use it from the dive list model. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-20Core: make helper functions globalGravatar Dirk Hohndel
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-20Core: debug helper for DOH constructorGravatar Dirk Hohndel
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-14Stop support Qt versions before 5.9Gravatar Dirk Hohndel
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-09Cloud storage: remove outdated certificate hackGravatar Dirk Hohndel
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-05Cleanup: remove bogus code that slipped in earlierGravatar Dirk Hohndel
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-03Analyze gasswitches in CCR bailoutGravatar Robert C. Helling
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-02Avoid duplicate debug output from GPS moduleGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-02Import: keep dive and dive site tables in DiveImportedModelGravatar Berthold Stoeger
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-02Cleanup: make table argument to get_dive_from_table() constGravatar Berthold Stoeger
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-02Cleanup: remove dive_table and dive_site_table Q_METATYPEsGravatar Berthold Stoeger
These are not passed through QML anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02Import: remove QML properties from DownloadThreadGravatar Berthold Stoeger
QML doesn't access these directly anymore but goes via the model. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02Core: implement move functions for dive and dive_site tableGravatar Berthold Stoeger
To allow efficient moving of downloaded dives from the download thread to the model, implement a general move function that moves table data. Instantiate that function for the dive and dive_site tables. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-27Revert the singleton PRGravatar Dirk Hohndel
It turns out that this isn't working the way it was intended to. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-09-25Cleanup: remove GpsLocation::instance() functionGravatar Berthold Stoeger
The last user was removed in 8576edd8d611f06fcbd452d88bbc3d46c39d1b9f. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-25Cleanup: unify idiosyncratic singletonsGravatar Berthold Stoeger
The way we handle singletons in QML, QML insists on allocating the objects. This leads to a very idiosyncratic way of handling singletons: The global instance pointer is set in the constructor. Unify all these by implementing a "SillySingleton" template. All of the weird singleton-classes can derive from this template and don't have to bother with reimplementing the instance() function with all the safety-checks, etc. This serves firstly as documentation but also improves debugging as we will now see wanted and unwanted creation and destruction of these weird singletons. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-25Cleanup: remove GpsLocation::hasInstance()Gravatar Berthold Stoeger
This function was not used anywhere. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-21Core: add unique id to tripGravatar Berthold Stoeger
To make it easier to pass around trips through QML, give each trip a unique id. The id is generated in alloc_trip() and uses the same function to generate unique dive ids. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-21Export: move dive site selection logic to C++Gravatar Berthold Stoeger
When exporting dive sites, the dive sites to be selected were collected in the C-core. But that doesn't have access to the selected dive sites if in dive site mode. Therefore, collect the dive sites in C++ and pass down to the core. Use a std::vector to avoid memory management woes. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-21Cleanup: make location argument to put_location() constGravatar Berthold Stoeger
Since this is an output function, the pointed-to value is not modified. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-21Cleanup: replace is_dive_site_used() by is_dive_site_selected()Gravatar Berthold Stoeger
is_dive_site_used() had a "selected" parameter. If true it would return whether the given dive site had a selected dive. Turns out all callers had this parameter set to true. Therefore, replace by a simplified function without the "selected" parameter and give the function an appropriate name. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-21Cleanup: make two functions in core/save-xml.c of static linkageGravatar Berthold Stoeger
These functions were not used outside of the core/save-xml.c. Make them local. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-21Android: bundle default font for use in OnePlus devicesGravatar Dirk Hohndel
This is working around a Qt Bug https://bugreports.qt.io/browse/QTBUG-69494 which prevents correct rendering of the OnePlus fonts. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-09-21Android: print Android HW informationGravatar Dirk Hohndel
This uses Android methods through JNI. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-09-21Android: add FTDI based DiveSystem / Ratio / Seac dive computersGravatar Dirk Hohndel
This way they can be used on a mobile device that supports our way of doing USB on Android. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-09-14Grantlee: split out grantlee-only property from DiveObjectHelperGravatar Berthold Stoeger
The cylindersObject list was only used by grantlee but not by the mobile code. Since it is quite heavy, split it out and thus don't generate it for every dive on mobile. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-14Mobile: transform DiveObjectHelper into value-typeGravatar Berthold Stoeger
Instead of handing a reference-to-dive to QML, prerender all the needed properties and store them as values in DiveObjectHelper. Exception: - date(): generated from timestamp - time(): generated from timestamp - cylinderList(): does not depend on dive anyway and should be made static. This hopefully avoids the random mobile crashes that we are seeing. Clearly, this code needs to be optimized, but it is a start. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-14Cleanup: make cylinder_t argument to CylinderObjectHelper constGravatar Berthold Stoeger
CylinderObjectHelper copies state from the passed in cylinder_t but does not modify it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-14Cleanup: remove unused function DiveObjectHelper::cylinder(int)Gravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-14Cleanup: remove unused function DiveObjectHelper::weight(int)Gravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>