This is a long commit, because it introduces a new abstraction:
a general std::vector<> of std::unique_ptrs<>.
Moreover, it replaces a number of pointers by C++ references,
when the callee does not suppoert null objects.
This simplifies memory management and makes ownership more
explicit. It is a proof-of-concept and a test-bed for
the other core data structrures.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
It was never clear what was a pointer to a static string from
libdivecomputer and what was allocated.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was the umpteenth inefficient reinvention of a trivial
map. Replace by a hash-map (std::unordered_map). Might just
as well use a balanced binary tree or a sorted array. In the
end, it probably doesn't matter at all.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
uemis_get_divenr() returns maxdiveid and passes mindiveid as a
global variable.
Make this more reasonable by returning a min, max pair.
The way mindiveid is an unsigned int and then reinterpreted as
int is very sketchy. This commit attempts to not change that
behavior.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is only initialized and used in one loop. Very mysterious
why this should be a global variable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This global variable is used in two function independently of
each other. I don't see how there should be transport of this
value from one function to the other. Ominous.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
uemis_get_answer() would put the raw response into a global variable.
This could be anywhere in the call stack and thus you never knew
when the existing buffer was removed under your feet.
Instead, return the buffer explicitly from uemis_get_answer().
I'm nit perfectly happy about the new interface: an error is
indicated by an empty buffer, which is awkward to test for.
If an empty buffer turns out to be a valid response, this
should be replaced by an std::optional<> or std::expected<>.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The string code of uemis-downloader.cpp was broken in more ways
than can be listed here. Notably, it brazenly refused to free any
memory allocated for the parameters buffer.
Using std::string and std::string_view should plug all those
memory holes. That made it necessary to do some major refactoring.
This was done blind and therefore will break.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
newmax was an integer variable kept as a string. Very ominous.
Moreover, memory management seems to be broken:
1) The string is never freed.
2) The string is passed as value from do_uemis_import() to
get_matching_dives(), which passes it as reference to
process_raw_buffer(), which may reallocate it, which means
that do_uemis_import() now possesses a pointer to a free()d
string.
Simplify all that by making newmax an integer variable and
passing it as a reference from do_uemis_import() to
get_matching_dives().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There were a number of fprintf()s that escaped the conversion
to report_info(), because they used "debugfile" instead of
"stderr" as target. However, debugfile was just #defined to
be stderr, so we might just use report_info() for consistency.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The uemis code is wild. It simply doesn't deallocate memory
and uses global variables. To get this under control, create
a "struct uemis" and make the functions exported by "uemis.h"
members of "struct uemis". Thus, we don't have to carry around
a parameter for the state of the importing process.
Turn a linked list of "helper" structures (one per imported dive)
into a std::unordered_map, to fix leaking of the helper structures.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Convert some C-style strings in uemis-downloader.cpp to std::string.
This has the side effect of fixing builds on Debian Trixie, which
currently fail with the (rather silly) error:
/build/subsurface-beta-202405060411/core/uemis-downloader.cpp: In function 'char* build_ans_path(const char*, int)':
/build/subsurface-beta-202405060411/core/uemis-downloader.cpp:290:32: error: '%s' directive output between 0 and 12 bytes may cause result to exceed 'INT_MAX' [-Werror=format-truncation=]
290 | snprintf(buf, len, "%s/%s", path, name);
| ^~
......
529 | ans_path = build_filename(intermediate, fl);
| ~~
cc1plus: some warnings being treated as errors
Signed-off-by: Richard Fuchs <dfx@dfx.at>