Commit Graph

1209 Commits

Author SHA1 Message Date
Christopher Lam
f67233b662 Bug 799305 - Crash when there is more than one unknown quote source for commodities
instead of vector which requires reallocation, use a c++ linked list.
2024-05-10 07:42:50 +08:00
Christopher Lam
d867a9d18a Merge branch 'TransactionP-hpp' into stable #1928 2024-05-05 14:36:43 +08:00
Christopher Lam
9e4b03f71b [SplitP.hpp] rename to .hpp 2024-05-05 14:35:44 +08:00
Christopher Lam
1e1d21b716 [Transaction.hpp] rename to .hpp 2024-05-05 14:35:38 +08:00
Christopher Lam
ef8afedd09 [gnc-euro.cpp] use c++isms 2024-05-05 09:28:32 +08:00
Christopher Lam
3bc7ce606d [gnc-euro.cpp] convert to c++ 2024-05-05 09:28:32 +08:00
Christopher Lam
80997ee5b4 [gtest-gnc-euro] add rounding test 2024-05-05 09:28:32 +08:00
Christopher Lam
949c9c97c0 Bug 799300 - Nullpointer exception in gnc_quote_source_s
avoids constructing std::string with nullptr
2024-05-04 08:27:43 +08:00
Christopher Lam
87dbbf25f8 [account.cpp] add gnc_account_foreach_until_date
- uses binary search to find first split after date
- for_each from earliest split to (but excluding) the above first split
2024-05-02 22:21:31 +08:00
John Ralls
9c18bc889c Don't use Googletest internal API for unused decls. 2024-04-22 18:05:10 -07:00
Bruce P Schuck
d01aad68fb Update gnc-commodity.cpp
Fool.pm not working. Removed references to it from sources JSON structures.
2024-04-22 18:05:10 -07:00
Bruce Schuck
6696bf0a41 Updated QuoteSourceVec to match F::Q v1.59 2024-04-22 18:05:10 -07:00
Christopher Lam
0f791c474a [Account.cpp][api] gnc_account_foreach_split takes std::function<void(Split*)> 2024-04-22 07:49:40 +08:00
Christopher Lam
871f669a19 [Account.cpp] explicitly destroy priv->splits
better than 35b6fb767d
2024-04-20 10:08:56 +08:00
Christopher Lam
35b6fb767d [Account.cpp] ensure priv->splits releases memory on shutdown 2024-04-19 18:55:05 +08:00
Christopher Lam
94368f4cb4 [Account.cpp] SplitsVec&, ensure xaccAccountGetSplitList is freed 2024-04-16 21:41:48 +08:00
Christopher Lam
2b71219766 [Account.cpp] remove obsolete comment 2024-04-16 07:30:15 +08:00
Christopher Lam
1b50c6261a g_list_free xaccAccountGetSplitList 2024-04-16 00:09:52 +08:00
Christopher Lam
606da28d25 use xaccAccountGetSplitsSize 2024-04-16 00:09:52 +08:00
Christopher Lam
f70ee754fc use xaccAccountGetSplits and gnc_account_find_split 2024-04-16 00:09:52 +08:00
Christopher Lam
3f7a5a8267 [Account.hpp][API] xaccAccountGetSplits and gnc_account_find_split 2024-04-16 00:09:52 +08:00
Christopher Lam
a54caaab61 [Account.cpp] GetBalanceAsOfDate gets std::function instead of bool 2024-04-15 23:21:16 +08:00
Christopher Lam
cc10b9a0b7 [SX-book.c] tidy for loop
because splits will need to be g_list_free in a future commit
2024-04-15 22:22:48 +08:00
Christopher Lam
c1ee59c39b [Account.h] size_t xaccAccountGetSplitsSize returns g_list_length (splits)
which is easily replaced with vector.size()
2024-04-14 23:29:20 +08:00
Christopher Lam
f08e0f5b61 [policy.cpp] rewrite to avoid goto 2024-04-14 23:29:20 +08:00
Christopher Lam
2251bf8966 [Account.hpp] use std::optional for cached values
whereby {} denotes uncached values
2024-04-13 20:56:55 +08:00
Sherlock
f0d45de642
Resolve test assert. 2024-04-12 15:52:39 -07:00
Sherlock
8d6f748aca
Bug 799281 - Deleting a transaction may trigger a crash
Update qof_collection_lookup_entity() to prevent returning instances marked to be destroyed.
2024-04-12 15:34:14 -07:00
Christopher Lam
d100df7ef7 [AccountP.hpp] .h -> .hpp, remove extern "C" {} wrapper 2024-04-02 21:09:40 +08:00
Christopher Lam
a67e4651c3 [Query.cpp] convert to cpp 2024-04-02 21:09:40 +08:00
Christopher Lam
4d9836aac2 [TransLog.cpp] convert to cpp 2024-04-02 21:09:40 +08:00
Christopher Lam
093781c018 [policy.cpp] convert to cpp 2024-04-02 21:09:40 +08:00
Christopher Lam
f913bed7e6 [gnc-engine.cpp] convert to cpp 2024-04-02 21:09:40 +08:00
Christopher Lam
96f041a1d6 [cap-gains.cpp] convert to cpp 2024-04-02 21:09:39 +08:00
Christopher Lam
79b7267cdd [cashobjects.cpp] convert to cpp 2024-04-02 21:09:39 +08:00
Christopher Lam
67d024c11f [Scrub3.cpp] convert to cpp 2024-04-02 21:09:39 +08:00
Christopher Lam
6b5a4d7c11 [Scrub2.cpp] convert to cpp 2024-04-02 21:09:39 +08:00
Christopher Lam
ddfa664601 [Scrub.cpp] convert to cpp 2024-04-02 21:09:39 +08:00
Christopher Lam
dab32807ef [engine/*.cpp] NULL -> nullptr changes
It's the done thing
2024-04-02 21:09:39 +08:00
Christopher Lam
9a85eb4a2a [engine/*.h] add extern "C" {} wrappers 2024-04-02 21:09:39 +08:00
Gwyn Ciesla
5132476a2f Allow building with c++20 and greater/ 2024-04-01 15:21:31 -05:00
Christopher Lam
4945db6b7d [AccountP.h] remove struct members obsolete with 76014f18a0
forgot to remove
2024-03-29 22:08:40 +08:00
Christopher Lam
ba403e4a7c [guid.hpp] GUID::from_string and is_valid_string takes a const char*
boost::uuids::string_generator has operator()(const char*).

thus we can avoid allocating std::string, with a consistent 4% speedup
2024-03-17 09:07:59 +08:00
Christopher Lam
cba7da30fd [gnc-date.cpp] specialise iso-8601 parsing where TZ=+0000
- avoid allocating new TZPtr
- parse y/m/d/h/m/s and construct PTime directly
- avoid boost's time_from_string which creates an std::string
2024-03-14 08:48:31 +08:00
Christopher Lam
27c16517e9 [gnc-numeric.cpp] shortcut parsing num/denom as gnc_numeric
The gnc_numeric is serialised as "num/denom" with no whitespace, and
denom > 0. This function takes advantage of std::from_chars to parse
it. The "num" serialisation is also optimised as a free side effect of
this function.
2024-03-11 19:16:06 +08:00
Christopher Lam
11da03bc67 [gtest-gnc-numeric.cpp] test int64 limits for GncNumeric 2024-03-11 19:15:48 +08:00
John Ralls
af18ea598e Bug 799093 - Cannot reconcile since v5.4
Covers the final case where having the reconcile window open and
auto-completing a transaction then deleting the transaction before
committing it leaves the transaction in the reconcile window.

We need to signal that the account is modified even if it isn't
because that's what the reconcile window is watching.
2024-03-11 10:20:02 +01:00
John Ralls
2db6988e25 Remove bogus include. 2024-03-01 15:31:35 -08:00
John Ralls
8ebac5b596 Bug 799213 - SIGSEGV caused by revising an auto completed transaction
Calling xaccSplitDestroy without also calling xaccSplitCommitEdit then
deleting the split list before calling xaccTransCommitEdit prevents
xaccSplitCommitEdit from being called on the supposedly deleted
splits. Not only does this leak them it leaves them in the book
potentially with a dangling parent pointer.
2024-02-29 14:29:40 -08:00
Christopher Lam
229d9300cf [engine-helpers.h] key is a const char*
thus allowing compilation in cpp with stricter type checking
2024-02-25 22:39:38 +08:00
Christopher Lam
c345fc9d3c add #ifdef __cplusplus extern "C" {} wrappers to .h files 2024-02-25 22:39:38 +08:00
Christopher Lam
6cb2eeeaa8 Merge branch 'more-engine-cpp' into stable #1866 2024-02-22 07:39:35 +08:00
John Ralls
226bfea108 Fix a bunch of UB errors from ASAN about mismatched function types.
The casts fool the compiler but not the UB sanitizer.
2024-02-20 15:33:11 -08:00
John Ralls
7bd97f15d0 Fix transaction delete use-after-free, take 2.
The problem with take 1 was that the duplicate split uses the same lot
and account pointers without adding itself to those lists, causing
checks in unit tests to fail.
2024-02-20 15:10:05 -08:00
John Ralls
8546aa975e Revert "Fix two use-after-free issues found by address sanitizer."
This reverts commit 4dbf803041.

The use-after free errors are caused by the compiler reordering the
steps in xaccSplitFree and Transaction's do_destroy. Unfortunately the
corrections here caused trouble in other places, leading to test failures.
2024-02-19 21:11:54 -08:00
John Ralls
4dbf803041 Fix two use-after-free issues found by address sanitizer. 2024-02-19 14:33:43 -08:00
Christopher Lam
28cc26f207 [gnc-commodities.cpp] gnc_new_iso_codes is a std::unordered_map 2024-02-19 11:21:24 +08:00
Geert Janssens
00640f9ded Replace naked for loops with C++ algorithms 2024-02-18 23:18:16 +08:00
Geert Janssens
0732436e44 A few NULL/nullptr related cleanups 2024-02-18 23:18:16 +08:00
Christopher Lam
17f422f97c [gnc-commodity.cpp] convert quote_sources to vector
- all quote sources are now vector
- get_quote_source_from_type to convert QuoteSourceType to vector<gnc_quote_source>
- the quote sources are modifiable, therefore cannot be const:
see gnc_quote_source_set_fq_installed
2024-02-18 23:17:55 +08:00
John Ralls
266ae2a931 Bug 798946 - start/end of current/last quarter have off-by-one error
Calculating the quarter offset when the current month is less than the
beginning month of the fiscal year was inverted.
2024-02-17 12:52:17 -08:00
Christopher Lam
164453a858 [gnc-commodity.cpp] gnc_quote_source_get_index searches index
we can now remove init
2024-02-17 22:55:41 +08:00
Christopher Lam
5d16d025a6 [gnc-commodity.cpp] gnc_quote_source_s is a cpp class
... this ensures the new_quote_sources vector now doesn't leak anymore.
2024-02-17 22:55:41 +08:00
Christopher Lam
346499ae04 [gnc-commodity.cpp] gnc_quote_source_set_fq_installed takes a StrVec
instead of a GList* of strdup'd chars
2024-02-17 22:55:40 +08:00
Christopher Lam
47a1a56f16 [gnc-commodity.cpp] fq_version is a std::string
thus can free itself on exit
2024-02-17 22:55:40 +08:00
Christopher Lam
f49c2735e3 [gnc-commodity.cpp] initialize quote_sources at compile-time 2024-02-17 22:55:40 +08:00
Christopher Lam
d488faacb2 [gnc-commodity.cpp] Convert to cpp 2024-02-17 22:55:40 +08:00
Vincent Lucarelli
f5b7bf3401 removed old_internal_name from gnc_quote_source_s (deprecated) 2024-02-17 22:52:40 +08:00
Christopher Lam
9035391907 [test-commodities.cpp] add some tests for gnc_quote_sources 2024-02-17 22:43:52 +08:00
Christopher Lam
03c5309666 [gnc-lot.cpp] convert to cpp 2024-02-09 17:23:51 +08:00
Christopher Lam
7d8d8f83be [Recurrence.cpp] convert to cpp 2024-02-09 17:23:51 +08:00
Christopher Lam
783c3df3c0 [Transaction.cpp] convert to cpp 2024-02-09 17:23:51 +08:00
Christopher Lam
fc5d7f872e [Split.cpp] convert to cpp 2024-02-09 17:23:51 +08:00
Christopher Lam
698cc23051 Add #ifdef __cplusplus extern "C" {} wrappers to .h files 2024-02-08 21:26:47 +08:00
Christopher Lam
928f9245e6 [gtest-gnc-numeric] add operator comparisons
with example int64 numbers
2024-01-29 08:55:56 +08:00
Christopher Lam
9782918586 [account.cpp] add more account metadata - assoc account
the tag denotes the type of associated account eg. "dividend"
"capgains" "cash" "fees"
2024-01-26 20:54:20 +08:00
John Ralls
c87d480b0d Move gnc_list_formatter from gnc-date to gnc-ui-util.
It has nothing at all to do with dates.
2024-01-06 18:16:31 -08:00
John Ralls
b2fa3ef106 Bug 799210 - Bad encoding of accented chars in account names in...
"Import CSV" wizard

In MSWin the UnicodeString(char*) ctor assumes that the input string
is encoded in the current codepage, but the input to
gnc_list_formatter is encoded in UTF8. Use the static class function
UnicodeString::fromUTF8 instead.
2024-01-06 10:30:14 -08:00
John Ralls
e22a57ad26 Merge John Ralls's 'asan' into stable. 2023-12-08 14:56:29 -08:00
John Ralls
6834cb5025 Implement coverage option
To use pass -DCMAKE_BUILD_TYPE=Debug or Asan -DCOVERAGE=ON and build as
usual, then do ninja lcov-initialize && ninja check && ninja
lcov-collect. The result will be a directory, <Builddir>/Coverage
containing lcov tracefiles, including an aggregate file gnucash.info
which you can use for further processing. It will also report an overall summary.
Note that only C/C++ files are included.

There's one more target, lcov-generate-html, that you can run after
lcov-collect. It will generate a simple website in
<Builddir>/Coverage-HTML showing coverage by source directory (the
directories in <Builddir> have coverage for generated files). Each
directory path is a clickable link to a page that shows coverage for
each source file; the filenames link to a page for each showing which
lines have been exercised.
2023-12-08 14:53:02 -08:00
John Ralls
6bc12898a8 GncDate: Remove now-superfluous base parameter. 2023-12-08 13:49:28 -08:00
John Ralls
1e289cb2b8 GncDate: Remove pointless normalize_month function.
Suggested by Sherlock.
2023-12-08 13:47:24 -08:00
John Ralls
966cef19aa Bug 799156 - normalize_struct_tm() does not normalize seconds,...
minutes, and hours correctly.

Fix proposed by Sherlock.
2023-12-08 13:45:04 -08:00
John Ralls
5005c3cac8 Merge Sherlock's 'bug799151' into stable. 2023-12-07 17:31:33 -08:00
Sherlock
ae8492d73a Update test-gnc-date.c 2023-12-07 17:31:19 -08:00
Sherlock
5a7b6e9814 Bug 799151 - gnc_date_get_last_mday () does not account for,,,
leap years correctly.
2023-12-07 17:30:08 -08:00
Sherlock
07e94b4222 Bug 799152 - normalize_reldate_tm() does not handle dates with...
months greater than 11 or less than -11 correctly.
2023-12-07 16:53:05 -08:00
John Ralls
d8dacb86b2 Bug 799143 - FTBFS on 32bit architectures
Fix misuse of GUINT_TO_POINTER in 5e09b66.
2023-11-28 01:47:12 +00:00
John Ralls
92de074e49 Bug 799144 - Date Completion is broken after 5.4 upgrade
strptime will reasonable return false for an incomplete date but it
still fills in the parts of the struct tm that it understands, so bail
out of qof_scan_date_internal when it fails only if all three fields
are present.
2023-11-26 09:23:58 -08:00
John Ralls
ed4921271c Bug 799134 - Fails to build with GCC 14 (‘find_if’ is not a member...
of ‘std’; did you mean ‘find’)
2023-11-21 15:27:04 -08:00
Christopher Lam
1d26d99ddb [gnc-budget] use std::optional<gnc_numeric> instead of bool+gnc_numeric
more expressive
2023-11-18 08:59:32 +08:00
John Ralls
dd0b72cdb5 Fix global array index out of range.
Tests must set the account type to avoid errors in xaccAccountOrder.
2023-11-17 15:20:29 -08:00
Christopher Lam
8f7eecd3e9 Merge branch 'icu-list-formatter' into stable #1791 2023-11-10 18:58:35 +08:00
Christopher Lam
6940488d2d recurrencePeriodTypeToString and recurrenceWeekendAdjustToString g_strdup only when necessary
... for sql use only. xml use assumes they return a const char*.
2023-11-06 14:12:17 -08:00
Christopher Lam
12f4233396 recurrencePeriodTypeToString and recurrenceWeekendAdjustToString g_strdup only when necessary
... for sql use only. xml use assumes they return a const char*.
2023-11-06 17:37:17 +08:00
John Ralls
fa119f8d17 Split test other 2023-11-02 12:58:55 -07:00
John Ralls
e17ba3cc00 Fix UAF in xaccFreeSplit.
xaccSplitComputeCapGains creates gains_split pointers in both the Cap Gains Split and its Income split to the original split, but the original's gains_split pointer can point to only one of them, the Cap Gains split. When the original split is freed both the Cap Gains split's and its Income split need their gains_split pointers NULLed or when it's the Income split's turn to be freed it will try to deref the dangling pointer.
2023-11-02 12:58:55 -07:00
Sherlock
52f1076b30
Bug 799104 - "Asset Chart" broken 2023-10-13 16:58:54 -07:00
John Ralls
44c278a82c Fix GncDateEntry date parsing oddities.
The intent was always to default to today if the input string isn't
parsable, but two problems prevented that: First,
qof_scan_date_internal didn't check the return value of strptime and
return FALSE if it failed and second gnc_date_edit_get_date_internal
would unnecessarily munge a valid struct tm from gnc_tm_get_today_neutral.
2023-10-12 15:51:35 -07:00
Christopher Lam
ab7ead39ca use icu::ListFormatter to combine a list strings into a string 2023-10-02 17:52:54 +08:00