Commit Graph

744 Commits

Author SHA1 Message Date
Christopher Lam
9ec670f828 [test-commodities.cpp] add kvp setter/getter test 2021-08-31 23:16:42 +08:00
Christopher Lam
d4c8b36f9f [utest-Transaction.cpp] add kvp setter/getter tests
wasn't tested before
2021-08-31 23:16:42 +08:00
Christopher Lam
c3b50f0b58 [gnc-lot.c] fix - cache value properly 2021-08-31 23:16:42 +08:00
Christopher Lam
595e126a34 [account.cpp] modify set_kvp_string_tag to accept strstrip or nullptr
- will remove a second call to g_strstrip (g_strdup (str))
2021-08-31 23:16:42 +08:00
Christopher Lam
c5a6383b43 [account.cpp] fix - incomplete #1117
- init struct members properly to: is_unset and TriState::Unset
- test acct kvp "equity-type" for "opening-balance" instead of "true"
- cached account->color/sort_order/notes/filter gets strstripped
  similarly to previous behavior
2021-08-31 23:16:42 +08:00
Christopher Lam
001b34616f [Transaction.c] GValue string must be unset 2021-08-29 15:38:16 +08:00
Christopher Lam
a47bee97d6 [Split.c] GValue string must be unset 2021-08-29 15:38:16 +08:00
Christopher Lam
0ecbcb4ef1 [gnc-lot.c] GValue string must be unset 2021-08-29 15:38:16 +08:00
Christopher Lam
ac2afc7e13 [gncInvoice.c] GValue string must be unset 2021-08-29 15:38:16 +08:00
Christopher Lam
3bf49ed8d7 [Account.cpp] GValue string must be unset 2021-08-29 15:38:16 +08:00
Christopher Lam
e3af2f22f9 [gnc-commodity.c] cache user_symbol into commodity struct
Continuation of ff2ceb111 which introduced issue whereby user_symbol
returned could become stale, leading to invalid read fixed with
c398bef59. There are likely other user_symbol pointers becoming stale
without this commit.

This change will save the user_symbol into the commodity struct,
avoids gchar* becoming stale.
2021-08-29 15:38:16 +08:00
John Ralls
57f73d70c7 Merge Yordan Miladinov's denom_lcd into maint. 2021-08-27 12:34:07 -07:00
Christopher Lam
c6d8333811 Merge branch 'maint' 2021-08-27 20:33:31 +08:00
Christopher Lam
c55ab50349 [gnc-budget.c] gnc_budget_get_account_period_note to be freed by the caller 2021-08-24 23:02:15 +08:00
Yordan Miladinov
6cb509ea7d
fix an uncaught exception: denom_lcd may throw an overflow exception if casting lcm to int64_t fails 2021-08-24 00:58:31 +03:00
Christopher Lam
7e41efc232 Merge branch 'maint-speedup-and-leaks' into maint #1109
Speedup xaccSplitGetOtherSplit
2021-08-20 21:23:35 +08:00
Christopher Lam
ff2ceb111d [gnc-commodity] GValue must be unset 2021-08-20 17:02:58 +08:00
Christopher Lam
028bf9826b [Split] xaccSplitGetOtherSplit don't test book trading-accts
don't test trading-acct property when finding other split.
2021-08-17 13:04:34 +08:00
Christopher Lam
6bf5a618de qof_instance_get gchar* must be freed
A call to qof_instance_get expecting a gchar* receives a newly
allocated string which must be freed.
2021-08-15 09:49:06 +08:00
Christopher Lam
e4d808e674 [qofbook] qof_book_use_split_action_for_num_field: free a char*
qof_instance_get allocates a new char* which must be freed.
2021-08-13 08:58:07 +08:00
Christopher Lam
eafc290034 Merge branch 'maint' 2021-08-12 22:28:58 +08:00
Christopher Lam
40d886fa9d gnc_account_list_name_violations elements must be freed 2021-08-12 09:39:08 +08:00
Christopher Lam
4c37f6d4ef [account.cpp] gnc_g_list_stringjoin instead of repeated allocations 2021-08-12 09:19:34 +08:00
Christopher Lam
bedc85afa3 Merge branch 'maint-leaks' into maint #1101 2021-08-06 19:30:01 +08:00
Christopher Lam
0420ae6a66 [account.cpp] refactor gnc_account_list_name_violations 2021-08-06 17:31:36 +08:00
Christopher Lam
67bd513514 [account.cpp] rewrite gnc_account_foreach_descendant_until in C++ 2021-08-06 17:31:36 +08:00
Christopher Lam
17953441cb [account.cpp] refactor gnc_account_foreach_descendant 2021-08-06 17:31:36 +08:00
Christopher Lam
5698b67bf5 [account.cpp] refactor gnc_account_lookup_by_code 2021-08-06 17:31:36 +08:00
Christopher Lam
09e2e7613c [account.cpp] refactor gnc_account_lookup_by_name 2021-08-06 17:31:36 +08:00
Christopher Lam
bebc366e88 [account.cpp] refactor gnc_account_n_descendants 2021-08-06 17:31:35 +08:00
John Ralls
f0926d66c1 Merge Simon Arlott's 'qof-instance-dispose' into maint. 2021-08-05 11:45:14 -07:00
Christopher Lam
e6c33a39bc [account.cpp] refactor gnc_account_get_descendants{_sorted} 2021-08-06 00:23:12 +08:00
Christopher Lam
d2db43019c [account.cpp] internal function account_foreach_descendant
fast and efficient
2021-08-06 00:23:12 +08:00
Christopher Lam
de1ad9367a g_free gnc_ctime which returns a new gchar* 2021-08-05 21:42:31 +08:00
Simon Arlott
7a0ea190ca
qof_instance_dispose should always complete dispose processes
If QofInstancePrivate has no collection then qof_instance_dispose() returns
without completing the rest of its dispose processes, skipping removal of
its type string from the string cache resulting in a reference count leak.

Change the check for a collection so that it only affects the call to
qof_collection_remove_entity().
2021-08-05 08:56:51 +01:00
John Ralls
9062be3d47 Merge Simon Arlott's 'string-cache-fixes' into maint. 2021-08-04 14:26:27 -07:00
John Ralls
08bf3ec5b0 Merge branch 'maint' 2021-07-30 10:28:57 -07:00
Simon Arlott
4a5b5f3bf2
Don't cache the empty string
Avoid unnecessary reference counting for uses of the empty string.
2021-07-11 18:54:49 +01:00
Simon Arlott
320df7e409
Use const return values for string cache
This is a prerequisite for being able to return "" (which is const) and
none of the returned values should ever be modified.
2021-07-11 18:54:49 +01:00
Simon Arlott
4132939612
Avoid leaking string cache entries for "" in Transaction and Split
When g_object_new() is used, the strings that default to "" are added to
the string cache. These are then not correctly removed when updating them
with new values when cloning a Transaction/Split.

Use CACHE_REPLACE instead of CACHE_INSERT.
2021-07-11 18:52:09 +01:00
Robert Fewell
0f026f6a10 Bug 798221 - Transfer funds between accounts with different currencies crashes Gnucash on macOS
In the scrub function find_account_matching_name_in_list there was a
test for account names being the same for currency but condition was
backwards so was matching on account names being different. There was
also a g_list_free resulting in a double free which was removed.
2021-07-08 09:33:10 +01:00
Simon Arlott
08b56e9669
[gnc-pricedb] Don't lookup old prices when doing bulk updates 2021-07-05 21:57:34 +01:00
Christopher Lam
1b4d30b3b1 Merge branch 'maint' 2021-06-22 23:30:20 +08:00
Hong Xu
0fd0aca531 Explain out what AsOfDate means in the doc
As discussed at
https://lists.gnucash.org/pipermail/gnucash-user/2021-June/096893.html
2021-06-16 12:07:23 -07:00
John Ralls
601eb51361 Improve transaction sorting on effective num field.
Inspired by PR #983. Transaction sorting on num broke down if the
user had a non-numeric string or a number larger than an int in
the effective num field (might be split-action if the option is set).

The comparison first tries to use strtoull on the two strings and
compares the results. If they're both nonzero and different then the
numeric order is returned. If they're both nonzero but the same the
unconverted parts of each are passed to g_utf8_collate; if either is 0
then the whole strings are passed to g_utf8_collate. strtoull will
return 0 for a negative number.
2021-06-15 14:02:25 -07:00
John Ralls
985a6420fc Bug 798196 - not building with Boost 1.76 2021-06-12 16:47:35 -07:00
John Ralls
6aa35ea7fb Better fix for bug 798204, doesn't break trading account selection. 2021-06-12 16:42:10 -07:00
John Ralls
9eeff5dd7e Bug 798204 - Creation of Imbalance Accounts
Search recursively when getting account by name.
2021-06-12 15:21:50 -07:00
John Ralls
68ec80e68d Bug 798203 - g_assert fault while reversing transaction
* Re-commit the original transaction to ensure that there aren't
any stray trading splits.
* If the original and cloned transactions have a different number of
splits don't leak the cloned transaction.
* Check that the cloned transaction isn't NULL before trying to invert
it.
2021-06-12 13:37:25 -07:00
John Ralls
80d6749989 Bug 787813 - Price change from editing a transaction not reflected...
in pricedb.

Allow PRICE_SOURCE_SPLIT_REG to overwrite PRICE_SOURCE_XFER_DLG_VAL.
2021-06-10 11:29:34 -07:00
Christopher Lam
321b5efabc Merge branch 'maint-leaks' into maint #1019 2021-06-09 06:47:23 +08:00
John Ralls
42213c597c Bug 798199 - Pasting invalid value in date column crashes GnuCash
Catch boost::gregorian::bad_year in LDT_from_struct_tm and rethrow
std::invalid_argument for C wrappers to catch and handle.
2021-06-08 13:14:30 -07:00
Christopher Lam
b095d1e7da Revert "[qofquery] q->terms g_list members must be freed"
This reverts commit a3e3823ee7.

Already freed earlier in the same function.
2021-06-08 07:36:47 +08:00
Christopher Lam
c8a7b9edb3 [Account] g_value_unset 2021-06-07 07:54:36 +08:00
Christopher Lam
bfdec74a48 [qof-backend] gchar * gnc_path_get_pkglibdir must be g_freed 2021-06-06 11:03:04 +08:00
Christopher Lam
f6a9be45ba [Split] g_value_unset 2021-06-05 00:21:52 +08:00
Christopher Lam
36901c5751 [gncJob] g_value_unset 2021-06-05 00:21:52 +08:00
Christopher Lam
1824a30bd0 [gncinvoice] g_value_unset 2021-06-05 00:21:52 +08:00
Christopher Lam
badd976e11 [gnc-lot] g_value_unset 2021-06-05 00:21:52 +08:00
Christopher Lam
c9565abe8b [gnc-commodity] g_value_unset 2021-06-05 00:21:52 +08:00
Christopher Lam
302020fcb7 [gnc-budget] g_value_unset 2021-06-05 00:21:50 +08:00
Christopher Lam
ceeb1dff7a [scrub.c] g_value_unset 2021-06-05 00:21:21 +08:00
Christopher Lam
92cd437562 [Transaction.c] g_value_unset to release GValue string 2021-06-05 00:21:20 +08:00
Christopher Lam
3353d3950b [gnc-budget] g_value_unset GValue 2021-06-05 00:20:23 +08:00
Christopher Lam
a3e3823ee7 [qofquery] q->terms g_list members must be freed 2021-06-03 17:16:09 +08:00
Christopher Lam
8a6413342d [SchedXaction] free GList* 2021-06-02 22:04:54 +08:00
Christopher Lam
c5585ebe2c [gncInvoice] free GList* 2021-06-02 22:04:52 +08:00
Christopher Lam
d611538ae7 [gncTaxtable] free GSList* 2021-06-02 22:04:33 +08:00
Christopher Lam
b3101c9385 [gnc-pricedb.c] plug GList leak 2021-06-02 20:09:45 +08:00
Christopher Lam
8a56a00313 Modify documentation for gncEntryComputeValue
Modify documentation for be19b489e
2021-06-01 08:14:25 +08:00
Christopher Lam
b25a444140 Merge branch 'maint' 2021-05-14 21:16:48 +08:00
John Ralls
da3c511b6c Remove trading splits instead of trying to adjust them. 2021-05-12 09:00:51 -07:00
John Ralls
4f030aac6e Bug 798093 - Changing the symbol/abbreviation of a security...
after the trading account was created breaks GnuCash.

Revisited. The original changeset looked for a top level trading account
and a namespace account in the transaction currency; if either of those
accounts had been created in a different currency it would duplicate
them.

This commit will accept any such account regardless of commodity. If
more than one exists it will prefer the one in the root currency if
there is one, otherwise it will select the first one found.
2021-05-12 09:00:51 -07:00
John Ralls
18c72baddf Don't bother scrubbing for orphans if there's no transaction currency.
If it found one it would try to create an orphan account with no
currency which will crash later.
2021-05-11 14:43:45 -07:00
John Ralls
2b48fd375d Revert "Fix duplicate trading accounts."
This reverts commit ed486a58a4.
2021-05-03 17:16:23 -07:00
Hong Xu
888676eb31 from_price and to_price may be uninitialized in extract_comon_prices
Fix the compilation error on gcc 10:

    gnucash/libgnucash/engine/gnc-pricedb.c: In function ‘extract_common_prices’:
    gnucash/libgnucash/engine/gnc-pricedb.c:2469:40: error:
    to_price may be used uninitialized in this function [-Werror=maybe-uninitialized]
     2469 |     if (from_price == NULL || to_price == NULL)
           |                                        ^
           gnucash/libgnucash/engine/gnc-pricedb.c:2469:20:
           error: ‘from_price’ may be used uninitialized in this
           function [-Werror=maybe-uninitialized]
            2469 |     if (from_price == NULL || to_price == NULL)
                  |                    ^
2021-04-29 14:51:07 -07:00
Christopher Lam
ae7eb9b3ad [gnc-pricedb] extract common code into get_nearest_price
Extracts common code in:

* gnc_pricedb_get_nearest_before_price
* gnc_pricedb_get_nearest_price
* gnc_pricedb_get_latest_price
2021-04-26 07:16:25 +08:00
Christopher Lam
a2f5223148 [gnc-pricedb] use g_list_find and plug memory leak
found_coms was not being freed.
2021-04-26 07:16:25 +08:00
John Ralls
ed486a58a4 Fix duplicate trading accounts.
In many cases GnuCash would create a new trading account hierarchy
when one already existed because gnc_account_lookup_by_type_and_commodity
didn't check the account presented and didn't recurse down the
account hierarchy correctly.
2021-04-24 15:51:32 -07:00
John Ralls
2258e7a44e xaccAccountTypes was backwards
vs. the documentation. The unit tests and dialog-account were similarly
backwards, but the use in gnucash/import-export/ofx followed the docs.
2021-04-24 15:51:32 -07:00
Christopher Lam
5ce8f78f77 Merge branch 'maint' 2021-04-24 23:16:22 +08:00
Robert Fewell
e535ba5411 Change some functions to use const gnc_commodity for gnc_pricedb 2021-04-23 11:56:15 +01:00
Robert Fewell
e75308e684 Rename a couple of gnc-pricedb functions that have not been used.
To be more consistent change gnc_pricedb_lookup_latest_before_t64 and
gnc_pricedb_lookup_latest_before_any_currency_t64 to be of the form
'_nearest_before_' and add a missing utest.
2021-04-23 11:56:15 +01:00
Robert Fewell
d3bd7fda61 Add unit tests for new gnc-pricedb functions 2021-04-23 11:56:15 +01:00
Robert Fewell
4a491f7cde Change a couple of docbook definitions in gnc-pricdb.h 2021-04-23 11:56:15 +01:00
Robert Fewell
05507008c5 Add retrieval functions for price before the date given
Add a new function, gnc_pricedb_convert_balance_nearest_before_price_t64
that retrieves the balance using the last price dated before a
specified date like today for the preset value. This uses another new
function gnc_pricedb_get_nearest_before_price to do the retrieval.
2021-04-23 11:56:15 +01:00
Robert Fewell
b54c30e03d Bug 798148 - Chart of Accounts page Present(xxx) value wrong
If for some reason you have price information in the future for a
security, the present value is based on the price retrieved for the
greatest date and not a price which is before the current date.

To fix this use the 'xaccAccountGetBalanceAsOfDateInCurrencyRecursive'
function.
2021-04-23 11:56:15 +01:00
John Ralls
bbb4113a5a Bug 798156 - glib 2.68.0 breaks gnucash
Move all of the #include <glib> to before the extern "C" blocks
so that the include guards will protect against headers inside
the extern "C" block also including glib.h.
2021-04-20 11:03:23 -07:00
John Ralls
4eaa10c6be Another extern-C glib.h, for Windows this time. 2021-04-13 16:56:55 -07:00
Christopher Lam
d28ff20ff7 Merge branch 'maint' 2021-03-29 17:29:19 +08:00
John Ralls
27435b1038 Don't filter use of TTInfo file section based on sizeof time_t.
The whole point of GncDateTime is to work around 32-bit time_t.
2021-03-22 14:23:23 -07:00
John Ralls
b40589244c Fix test-gnc-datetime failure on Ubunutu. 2021-03-22 14:18:24 -07:00
John Ralls
c49b45d8f1 Finish the glib 2.67 fixes for CI tests. 2021-03-22 14:02:37 -07:00
John Ralls
1221d7ebc1 Bug 798150 - Error on report over time
Extract functions LDT_from_date_time and LDT_from_date_daypart
to avoid duplicate code. Handle date-times in start-of-DST transitions
and better handle those in end-of-DST transitions. Test the results.
2021-03-21 15:55:08 -07:00
John Ralls
ebb5eb1f17 Fix GncDateTime::format_zulu to emit the UTC timezone.
Instead of the GncDateTime's timezone with the UTC timestamp.
2021-03-21 15:55:08 -07:00
John Ralls
3a35514d84 Fix the implementations of gnc_foo_get_day_neutral.
As implemented these returned 10:59 AM local on the day but neutral
time is 10:59 UTC.
2021-03-20 09:45:38 -07:00
Christopher Lam
2a2f080813 Merge branch 'maint' 2021-03-18 07:36:40 +08:00
Frank H. Ellenberger
4a983761d7 Fix a typo in a comment of the last commit 2021-03-16 06:34:08 +01:00
John Ralls
a11065b823 Fix fencepost error in calculating the week_num for POSIX timezone rules.
Fixes CI failure caused by US starting DST in 2021, a year in which
March began on a Monday.
2021-03-15 17:07:16 -07:00
John Ralls
8e41857014 Catch more exceptions in gnc_numeric_convert
To enable fixing https://bugs.gnucash.org/show_bug.cgi?id=798132.
2021-03-12 13:47:24 -08:00