aboutsummaryrefslogtreecommitdiffstats
path: root/core
AgeCommit message (Collapse)Author
2020-10-26cleanup: replace deprecated sprintf()/vsprintf() callsGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-26cleanup: initialize all members of weightsystemGravatar Dirk Hohndel
The auto_filled member was recently added and not initialized in the UEMIS downloader. Fixes CID 362080 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-26cleanup: fix resource leakGravatar Dirk Hohndel
Fixes CID 362078 Fixes CID 362081 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-26cleanup: fix resource leakGravatar Dirk Hohndel
And address typo in comment. Fixes CID 362915 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-25filter: use 64-bit integer literal for generating bit fieldsGravatar Berthold Stoeger
For multiple-choice constraints we use a bit field of type uint64_t. This means we theoretically support up to 64 items. Currently use at most seven. Coverity complained (correctly) that we use the expression "1 << x" to generate the bitfields. However 1 is a 32-bit literal on most platforms, which makes this undefined behavior for x >= 32. Change the integer literal to 64-bit 1ULL. Moreover, when detecting items with an index >= 64, don't even attempt to set the according bit, since this is undefined behavior and the compiler is free to do as it pleases in such a case. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: remove pref.h include in dive.hGravatar Berthold Stoeger
If source files want to access preferences functions, they should include pref.h themselves. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: move git-pref declarations into core/pref.hGravatar Berthold Stoeger
These seem to be an artifact. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: move sort_dive_table declaration to divetable.hGravatar Berthold Stoeger
Apparently this was forgotten in a previous include-reshuffling. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: move cylinder_use_text declaration to equipment.hGravatar Berthold Stoeger
This is unrelated to struct dive and also wasn't defined in dive.c Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: remove unused macros / declarations from dive.hGravatar Berthold Stoeger
Nobody was using these return-code macros and the functions do not exist since a long time. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: move interpolate inline function to its own header fileGravatar Berthold Stoeger
This is not really related to struct dive, so let's move it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: remove system includes from dive.cGravatar Berthold Stoeger
Let the various source files include the system headers they need themselves. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: move application flags to core/subsurfacehelper.hGravatar Berthold Stoeger
These flags are not dive-related, therefore move their declaration to the appropriate header file. Likewise, move their definition from parse-xml.c to subsurfacehelper.c Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: move function declarations to divelist.hGravatar Berthold Stoeger
unregister_dive() and delete_single_dive are defined in divelist.c, as they take an "index" argument into the global divelist. Therefore, move their declarations to divelist.h. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: split out divecomputer functions from dive.cGravatar Berthold Stoeger
Since dive.c is so huge, split out divecomputer-related functions into divecomputer.[c|h], sample.[c|h] and extradata.[c|h]. This does not give huge compile time improvements, since struct dive contains a struct divecomputer and therefore dive.h has to include divecomputer.h. However, it make things distinctly more clear. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: remove get_times() functionsGravatar Berthold Stoeger
The function 1) was misnamed: it determined the time of the first selcted dive. 2) had only one caller. 3) would crash if there was no selected dive. Let's just fold the functionality into the caller. It's a one-liner anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: move fill_pressures from dive.c to gas.cGravatar Berthold Stoeger
This function does not access a dive structure. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: break out event-related code into event.[c|h]Gravatar Berthold Stoeger
In an effort to reduce the size of dive.h and dive.c, break out the event related functions. Moreover event-names were handled by the profile-code, collect that also in the new source files. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: move mark_divelist_changed() to qmlmanager.cppGravatar Berthold Stoeger
Desktop does not use mark_divelist_changed() anymore - all is done via the undo machinery. Therefore move this function (and its counterpart unsaved_changes()) to qmlmanager.cpp. Ultimately, it probably should be removed from there as well, but currently I don't dare to touch all the cloud-logic! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25devices: add index based device removal functionGravatar Berthold Stoeger
The undo machinery will need a method to remove devices based on their index instead of their name. Add it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25undo: add device related undo commandsGravatar Berthold Stoeger
Add commands for deleting devices and editing device nicknames to include the device-handling in the undo system. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: initialize all fieldsGravatar Dirk Hohndel
This doesn't appear likely to cause an issue, but also doesn't seem wrong. Fixes CID 350734 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-25cleanup: fix over-eager Coverity warningsGravatar Dirk Hohndel
Technically get_dive() could return a nullptr. The existing code made sure the argument passed to get_dive() was one that always would result in a valid dive pointer being returned. The new code is only slightly less efficient but allows a static code analysis to easily see that we don't derefence NULL pointers here. On some level this change is unnecessary. But it's also not wrong. Fixes CID 354762 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-25cleanup: remove double const qualifierGravatar Berthold Stoeger
The redundant qualifier was introduced in an erroneous rebase. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24core: remove create_device_node() from fixup_dive()Gravatar Berthold Stoeger
The device nodes are created for all DCs, when importing the dives. There is no point in creating only the device node for the first DC in fixup_dive(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24divecomputer: add device to provided table instead of global tableGravatar Berthold Stoeger
In the specuial case of suunto, where we may add a device directly instead of via dive->dc, add the device to the provided table. The caller will then pass on the new device to the undo system. This makes downloading finally really undoable (at least I hope so). So far, the dives and dive sites were removed, but any new device remained. However, when setting the device-id via serial, we now have to check both, the global and the downloaded list of devices. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24divecomputer: add device_table pointer to device_data_tGravatar Berthold Stoeger
In one weird case (suunto), the code in libdivecomputer.c generates a device node directly instead of going the usual way (setting the data in the dc-structure of the imported dive). It is unclear to me whether that has to be that way, as it depends on the chronological order of callbacks to event_cb() and dive_cb(). Therefore add a device_table pointer to device_data_t so that the downloader can add the device to this table. This only adds the pointer, but does not yet use it in the downloading code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24cleanup: remove dc_user_device_tGravatar Berthold Stoeger
The same structure was defined as "struct dc_user_device_t" and typedefed as "device_data_t". Unify this. Since there are much more of the latter, remove the former. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24devices: create device nodes in parsersGravatar Berthold Stoeger
So far, we added a non-global device table to the parser states. Now, create device nodes in that table instead of in the global table. Thus, on undo of dive-import, the new device nodes will be removed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24git: add device-table to git-parser-stateGravatar Berthold Stoeger
In analogy to the xml-parser add a device-table to git's parser-state. Currently this is unused. In upcoming commits the git parser will then be changed to add device nodes in this table instead of the global device table. The long-term goal being to detach the parsers from global state and to make dive-import fully undoable. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24cleanup: rename set_dc_nickname() to add_devices_of_dive()Gravatar Berthold Stoeger
The function was misnamed in that it doesn't set the nickname of a device. Instead, it adds all (unknown) devices of a dive to the/a device-table. Let's call it appropriately. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24devices: add devices in Command::importTable()Gravatar Berthold Stoeger
Add a device_table parameters to Command::importTable() and add_imported_dives(). The content of this table will be added to the global device list (respectively removed on undo). This is currently a no-op, as the parser doesn't yet fill out the device table, but adds devices directly to the global device table. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24devices: return index from function adding / removing devicesGravatar Berthold Stoeger
This will be used to keep the model representing the device-list up to date. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24devices: add functions to add / remove / check for devicesGravatar Berthold Stoeger
To include the device code in the undo system, we need functions to check for the existence of devices and to add or remove them. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24parser: add device_table to parser stateGravatar Berthold Stoeger
If we want to avoid the parsers to directly modify global data, we have to provide a device_table to parse into. This adds such a state and the corresponding function parameters. However, for now this is unused. Adding new parameters is very painful and this commit shows that we urgently need a "struct divelog" collecting all those tables! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23cleanup: remove unused function intdup()Gravatar Berthold Stoeger
That was used by the old xml-params code, which was recently replaced. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23parser: replace params[] code by new xml_params structGravatar Berthold Stoeger
This fixes a load of memory holes, and makes the code (hopefully) more readable. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23core: add a small helper-struct that keeps track of xml-parametersGravatar Berthold Stoeger
The XML-parameter code is a mess. Ownership is unclear. Allocation and freeing of strings is in different functions. Sometimes only every second string is free()d, because keys are not copied. But this is done inconsistently. The caller has to know how many parameters the callee may add. Instead, let's add a small helper-struct that uses C++ memory management, but exports a C-API. The array for the XML-library is generated on the fly. This is only the implementation, the old code is not yet replaced. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23libdc: free value strings given by libdc's dc_parser_get_field()Gravatar Berthold Stoeger
Apparently libdc gives us copies of strings. The API is very scary, because (at least according to my reading of the code), the key/value pair may be stored in a cache. Thus on free()ing the string in the cache becomes invalid and we must not access it twice. Very obscure. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17devices: use case-insensitive comparison for modelGravatar Berthold Stoeger
Recently, the sorting of the devices was changed to be case-insensitive for models for consistency reasons. However, then the equality-comparison should also be case-insensitive. Break it out into its own function, to avoid that mistake in the future. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17cleanup: rename clear_device_nodes() to clear_device_table()Gravatar Berthold Stoeger
For consistency with all the other clear_*_table functions (dive, trip, dive_site, ...) Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17filter: remove filter_preset_table_tGravatar Berthold Stoeger
We used a typedef "filter_preset_table_t" for the filter preset table, because it is a "std::vector<filter_preset>". However, that is in contrast to all the other global tables (dives, trips, sites) that we have. Therefore, turn this into a standard struct, which simply inherits from "std::vector<filter_preset>". Note that while inheriting from std::vector<> is generally not recommended, it is not a problem here, because we don't modify it in any shape or form. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17filter: make filter_preset_table an opaque struct for C codeGravatar Berthold Stoeger
filter_preset_table_t was defined as "void" for C code. However, that meant that any pointer could be passed as such a table and such a table could be passed as any pointer, without generating compiler warnings. Indeed, we had a parameter-mixup that went unnoticed. Therefore, make filter_preset_t an anonymous structure with the name filter_preset instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16cleanup: use correct printf formatGravatar Dirk Hohndel
This fixes a warning from the CodeQL scan. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-16core: use case-insensitive comparison for device modelsGravatar Berthold Stoeger
The code in core/libdivecomputer.c used string insensitive comparison for device models, before being merged into core/device.c. Let's reinstate that behavior, since it appears to be more logical. On would assume that two different vendors will not use the same model with different casing (and the same device-ids), so that should be safe. This uses strcoll to correctly sort unicode, which will hopefully never be needed! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16cleanup: replace std::find_if by std::any_ofGravatar Berthold Stoeger
To search for devices with the same model, we used find_if(). However, that was only to check whether such a thing exists, not to actually do something with said device. Therefore, change this to std::any_of() to make it clear what the purpose of the statement is. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16core: add device_table parameter to device table functionsGravatar Berthold Stoeger
Instead of accessing the global device table directly, add a parameter to all device-table accessing functions. This makes all places in the code that access the global device table grep-able, which is necessary to include the device-table code in the undo system. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16core: remove call_for_each_dc()Gravatar Berthold Stoeger
The core now loops over the devices directly - no need for this callback. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16core: use C accessors in core/save-xml.c instead of callbackGravatar Berthold Stoeger
We now can loop over devices from C and check for selection. So let's get rid of the last user of the call_for_all_devices() callback. Code readability improvement is not stellar, but one less place where we shoe-horn user data through a void-pointer. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16core: factor out device_is_used_by_selected_dive() functionGravatar Berthold Stoeger
We have a callback for all devices with a twist: it can loop over those devices that are used by a selected dive. This is used for exporting a subset of the dive log. Factor out the "is device used by selected dive" part of the function and make it available to C. The goal is to make the whole callback thing unnecessary and let C code loop directly over the device list. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>