aboutsummaryrefslogtreecommitdiffstats
path: root/core
AgeCommit message (Collapse)Author
2019-11-09Core: dynamically allocate cylinder maps in merge_cylinders()Gravatar Berthold Stoeger
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-09Core: dynamically allocate gases arrayGravatar Berthold Stoeger
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-09Profile: dynamically allocate gases arrayGravatar Berthold Stoeger
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-09Profile: dynamically allocate plot pressure dataGravatar Berthold Stoeger
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-09Profile: use pressure data functions in save_profiles_bufferGravatar Berthold Stoeger
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-09Profile: use pressure data functions in fill_missing_tank_pressuresGravatar Berthold Stoeger
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-09Profile: turn INSERT_ENTRY macro into helper functionGravatar Berthold Stoeger
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-09Profile: pass index instead of pointer to set_plot_pressure_dataGravatar Berthold Stoeger
Another plot-pressure-related function whose argument is converted to an index. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Profile: switch pressure-accessing functions to indexesGravatar Berthold Stoeger
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-09Profile: change get_plot_pressure to take index instead of pointerGravatar Berthold Stoeger
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-09Cylinders: dynamically allocate cylinder arraysGravatar Berthold Stoeger
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-09Core: dynamically allocate the result of get_gas_used()Gravatar Berthold Stoeger
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-08core: reorder dive structure elements to avoid paddingGravatar Dirk Hohndel
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-08core: add collapsed state to the dive data structureGravatar Dirk Hohndel
This is only used in Subsurface-mobile. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-11-03Planner: Don't accumulate rounding errors in stop durationsGravatar Robert C. Helling
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-10-31Planner: Add option to treat O2 as narcoticGravatar Robert C. Helling
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-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>