Commit graph

20282 commits

Author SHA1 Message Date
Michael Keller
8a5009786e Fix Translation Error in Android Build.
Same as iOS.

Signed-off-by: Michael Keller <github@ike.ch>
2024-03-16 13:32:02 +13:00
Dirk Hohndel
153bcdec42 fix incorrect Italian localization on iOS
Stupid cut and paste error...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2024-03-15 07:50:29 -07:00
Michael Keller
e6ff3f7537 Cleanup: Fix Problems Raised by Coverity Scan.
Opportunistically fix some problems newly raised by a recent Coverity
scan.

Not touching any of the string memory allocation issues as this is being
handled by the move towards C++ strings.

Signed-off-by: Michael Keller <mikeller@042.ch>
2024-03-14 11:42:09 +13:00
Berthold Stoeger
3229d1e3a1 preferences: replace macro by local function
No apparent reason for having this as a hard-to-read macro.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-13 13:17:01 +13:00
Berthold Stoeger
857148efd6 preferences: replace SIGNAL/SLOT by function pointers
This give compile time checking. In fact, one of the connections was
not working (currentIndexChanged(QString) doesn't exist in newer(?)
Qt versions).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-13 13:17:01 +13:00
Berthold Stoeger
8980d61786 core: replace SSRF_INFO macro by report_info()
The point of this macro is unclear. It just calls report_info()
anyway...

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-12 10:31:07 -04:00
Berthold Stoeger
bfbf4934dd core: enable compiler warngings for report_error and report_info
printf() is a horrible interface as it does no type checking.
Let's at least use the compiler to check format strings and
arguments. This obviously doesn't work for translated strings
and using report_error on translated strings is dubious. But OK.

Had to convert a number of report_error() calls to supress
warnings.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-12 10:31:07 -04:00
Berthold Stoeger
fcf0bda042 core: move report_info and SSRF_INFO to errorhelper.h
qthelper.h is an absolute monstrosity and it is unclear what
report_info and SSRF_INFO have to do with Qt.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-12 10:31:07 -04:00
Dirk Hohndel
d653cec7a4 ensure locale language info lands in the applog
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2024-03-11 11:30:14 -04:00
Dirk Hohndel
8f50c9c1b3 Improve automated language handling
This mimics the code added in commit cf990b0f39 ("preferences: choose language
code with one '-'") and adds some debugging for the mobile case - some people
are being presented with Subsurface-mobile in Korean for some reason.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2024-03-11 11:30:14 -04:00
Berthold Stoeger
c7a929a8a8 Correctly initialize string in core/device.cpp
When initializing a string with multiple characters, first
comes the length, then the size. Not the other way around.

Fixes #4127.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-11 20:20:18 +13:00
Berthold Stoeger
8b5812bc2c profile: fix uninitialized variable in DivePercentageItem
Fix bug introduced in 505e4e47eb.

Nobody complained, so not clear if that was user visible.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 17:59:32 +01:00
Berthold Stoeger
cf990b0f39 preferences: choose language code with one '-'
On initialization, the old code searched for the first language
code containing a '-'. However, my Qt version gives de-Latn-DE
as the first entry. That messed up the preferences code: it
didn't recognize that entry. Thus, simply opening and closing
the preferences switched the language to Bulgarian.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-09 22:11:11 -05:00
Berthold Stoeger
889ca23999 cleanup: automatically determine array size in load-git.cpp
There was a pattern of code like
match_action(line, state, dive_action, ARRAY_SIZE(dive_action));

The doubling of the array might cause copy & paste errors, where
only one array is replaced.

Therefore, determine the length of the array with (hopefully
easily understood) template tricksery.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
6bf8cbfe46 core: avoid pointless copying in git parser
When iterating over the converted strings of a line, the
first entry of the array would be popped off, leading to
a full copy of the remaining array.

Instead, use an index in the parser state.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
885ff44c56 core: directly generate std::strings in git parser
The converted strings were stored in a membuffer and later
converted to std::strings. Generate an std::string directly
to avoid unnecessary copying.

Ultimately, when the core structures are converted to
std::string, there should be no copying of the string data
at all (unless formatting is applied or small string
optimization kicks in, of course).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
6b054318e0 core: convert parse_mkvi_value() and parse_mkvi_key() to C++
This was a particularly funny one: It trampled on and then
restored the buffer.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
cca4c8cae5 core: return std::string from get_dive_date_c_string()
Had to convert uemis-donwloader.c to C++. Lot's of
non-const clean code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
203ff8b2e6 core: port string handling in divecomputer.cpp to C++
Replace formatstring() by the C++ version.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
ad7530f7bb core: use std::string for dummy hash value in parser
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
affcbddbb0 core: use std::string to format battery extra data
Create a format_string_std function that works like format_string,
but does return a std::string instead of a strdup()ed C string.

Make it a global function to be used in other parts of the code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
e6321a1305 core: turn extra_data key/value pair in parser to std::string
Less troublesome memory management.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
92a1a08b21 core: remove alloc_filter_preset() and free_filter_preset()
All users of that are now C++ and don't need these helpers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
cf7c54bd56 core: turn a memblock in the parser to std::string
This avoid memory-management troubles. Had to convert a few
of the parsers (cochran, datatrak, liquivision) to C++.
Also had to convert libdivecomputer.c. This was less
painful than expected.

std::string is used because parts of the code assumes
that the data is null terminated after the last character
of the data. std::string does precisely that.

One disadvantage is that std::string clears its memory
when resizing / initializing. Thus we read the file onto
freshly cleared data, which some might thing is a
performance regression. Until someone shows me that this
matters, I don't care.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
2f4dbf1848 core: make get_sha() return std::string
This was crazy: it returned a local static buffer, i.e. was
inherently non-reentrant.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
2f3d8d83f5 core: port printGPSCoordsC to return std::string
Less memory management hassle.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
119fe908c7 core: port filterpreset.cpp to std::string
Less memory management hassle.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
2e1d852e36 core: convert filter_constraint_data_to_string to C++
Return an std::string to avoid memory management headaches.

While doing that, convert time.c to C++ so that
format_datetime directly returns an std::string.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
898ecd2df5 core: make fp_get_data return an std::string
No need for manual memory management.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
8d96b7557d core: convert parser_state to C++
Add constructor, destructor and use std::string for memory
management of text data.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
5e466d91f0 core: convert core/import-*.c to C++
import-csv.c was crazy with implicit (const char *) to (char *)
conversions!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
83b0c1da40 core: convert parse-xml.c and parse.c to C++
This was very annoying, because the old code was not const-clean
at all and trampled all over buffers. This makes the new code
pretty messy for now.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
a133c6c4db mobile: turn testqml into a std::string
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
9509eb6876 divetripmodel: explicitly convert char * to QString
The automatic conversion from char * to QVariant failed to
compile for me. Let's hint that this should be interpreted
as a string. No idea, why this happens for me, but apparently
not on CI.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
43ec3fc1d9 core: use std::string in load-git.cpp
Make the memory management easier to follow. I feel that the old
code was leaking left and right, but not sure because it was so
intractable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
114513493b core: use std::string in parser state of git loader
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
a1826f77da core: turn saved_git_id into a std::string
Simplifies memory management. Think about unglobalizing this,
once everything is in C++ so that we can put an std::string
into struct divelog.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
c05be40bfd core: convert load-git.c to C++
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
d803e42314 core: convert file.c to C++
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
a032d9c979 core: convert save-xml.c to C++
This includes using the C++ version of membuffer. There appears
to not have been a leak, because the buffer is freed in
flush_buffer(), but usage was somewhat inconsistent and hard to
follow.

Also, convert some string handling to std::string to avoid free()
madness.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
76c2069fa8 core: port subsurface-startup.c to C++
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
f1012283a0 core: turn a few string helpers into C++
get_changes_made(), subsurface_user_agent() and normalize_cloud_name()
are only called from C++.

Avoids having to manually free the returned value and is therefore
more robust against leaks.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
924b23ed56 core: convert git-access.c to C++
Had to make sha.h compatible with C++.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
b0438ad1dd core: use C++-style memory management for struct dir
The code is now much easier to check for memory leaks,
since there are no explicit free()s. Yes, memory is not
released immediately, but that should be of no concern.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
371b155922 core: convert core/save-git.c to C++
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
148775f418 core: convert sample.c to C++ and add default constructor
This changes default behavior when creating a sample struct
in C++ code: it is now initialized to default values. If this
ever turns out to be a performance problem, we can either add
additional constructors or use special functions that do
not initialize memory, such as make_unique_for_overwrite.

This removes non-standard (respectively >C++20) constructs,
namely designated initializers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
c27e093ebd core: replace dynamic arrays in dive.cpp by C++ constructs
Avoid error-prone malloc/free pairs. This uses somewhat
obscure constructs to stay as close as possible to the
original C code. Notably, it uses mostly unique_ptr<T[]>
which doesn't store the length of the array, because the
length is supposed to be known.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
52e6a098aa core: convert dive.c to C++
Long term project: convert core to C++ so that we can
use higer-level constructs, notably std::vector<>.

This does not change any code - only fixes compile issues.

Mostly casting of (void *) to the proper type. Also designated
initialization of the sample struct had to be rearranged.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
096e49e15b core: make translate() accessible from C++
In the core, we usually want C strings, not QStrings. Therefore,
make translated C strings directly available from C++.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
transifex-integration[bot]
0ea287cc2c
Translate subsurface_source.ts in de_DE
100% translated source file: 'subsurface_source.ts'
on 'de_DE'.
2024-03-09 16:14:26 +00:00