Commit Graph

263 Commits

Author SHA1 Message Date
Christopher Lam
d100df7ef7 [AccountP.hpp] .h -> .hpp, remove extern "C" {} wrapper 2024-04-02 21:09:40 +08:00
Christopher Lam
6c82a1311b [sixtp-dom-parsers.cpp] use string_to_guint, string_to_guint16 2024-03-26 20:55:25 +08:00
Christopher Lam
249ec9f43a [test-string-converters.cpp] add some string->number tests 2024-03-26 20:55:25 +08:00
Christopher Lam
1f9ea6bc99 [sixtp-utils.cpp] std::from_chars speedup, remove string_to_gint32
Benchmarks running tests 4E6 times:

using sscanf

$ bin/test-string-converters
 elapsed=7.33942s
Executed 92000006 tests. All tests passed.
$ bin/test-string-converters
 elapsed=7.3811s
Executed 92000006 tests. All tests passed.
$ bin/test-string-converters
 elapsed=7.3455s
Executed 92000006 tests. All tests passed.

with std::from_chars

$ bin/test-string-converters
 elapsed=4.47369s
Executed 92000006 tests. All tests passed.
$ bin/test-string-converters
 elapsed=4.46908s
Executed 92000006 tests. All tests passed.
$ bin/test-string-converters
 elapsed=4.47067s
Executed 92000006 tests. All tests passed.
$ bin/test-string-converters
 elapsed=4.48706s
Executed 92000006 tests. All tests passed.
2024-03-26 20:55:00 +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
Christopher Lam
fdcb8b46bd [sixtp-dom-generators.cpp] char* must be freed 2023-11-11 12:45:57 +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
f67b53a440 Xml backend tests: Use libgnc-backend-xml-utils instead of sources.
Every test was rebuilding it except for gnc-backend-xml.cpp from
scratch, no point in that plus the Address Sanitizer needs the
definition of GncBackendXml.
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
John Ralls
2234fa433e Add Asan build type that enables the Address and UB sanitizers.
Uses generator statements instead of CMAKE_<TYPE>_FLAGS_ASAN to support multiconfig generators like Xcode.
2023-11-02 12:58:46 -07:00
Christopher Lam
d617129db8 avoid strlen where possible
if testing emptiness, test *str instead.
2023-11-01 22:43:16 +08:00
John Ralls
422fd0cab2 Fix misspelled/missing dist files. 2023-09-23 14:01:11 -07:00
John Ralls
90b9142096 [DBI backend] Change DBI test URLs to environment variables.
From cmake configuration definitions.
2023-09-21 14:33:50 -07:00
Christopher Lam
8e21d3328f guid_to_string should be freed. 2023-09-19 20:31:11 +08:00
Christopher Lam
55b9382ad9 [utest-gnc-backend-sql] properly clean up QofBook 2023-09-19 07:59:38 +08:00
Christopher Lam
c44194606a [test-xml-pricedb] free a sixtp parser 2023-09-15 23:55:06 +08:00
Christopher Lam
7ce4198c20 rename string_to_gnc_numeric to gnc_numeric_from_string 2023-08-29 08:45:20 +08:00
Christopher Lam
f8546dc4da Fix compilation error from 5781f3445b 2023-08-11 23:35:10 +08:00
John Ralls
5781f3445b SQLBackend: Use std::optional return value instead of exceptions
For wrong value type when retrieving a value from the SQL results row.

Profiling showed that most of the SQL load time was spent in handling
these exceptions, and using std::optional instead produced a > 11x
speedup (10 seconds vs. 115 seconds) when loading a large file.
2023-08-10 14:05:10 -07:00
John Ralls
4d46a8191d Merge Simon Arlott's 'test-xml-save' into stable. 2023-08-03 11:05:11 -07:00
Simon Arlott
35bee1382d
Test loading and saving XML files with and without compression
Add new test files that are written with the latest version of GnuCash.
Test loading them, saving to compressed files, loading those compressed
files and writing to an uncompressed file. At every stage check it matches
the canonical version.
2023-07-30 19:11:57 +01:00
Christopher Lam
867867da53 Merge Richard Cohen branch 'fix-leaks-in-tests' into stable #1713 2023-07-24 13:09:55 +08:00
Richard Cohen
1943caee55 Fix memory leak on error path in text_to_dom_tree() 2023-07-19 10:29:06 +01:00
Richard Cohen
2640911901 Valgrind: fix "definitely lost/still reachable" memory in test - test-xml2-is-file
Valgrind uses "still reachable" because of the call to exit()

==87185== 94 bytes in 1 blocks are still reachable in loss record 193 of 241
==87185==    at 0x4843828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==87185==    by 0x15C234: main (test-xml2-is-file.cpp:42)
==87185==
2023-07-19 10:21:30 +01:00
Richard Cohen
b7d278556f Valgrind: fix "definitely lost" memory in test - test-string-converters
==68902== 8 bytes in 1 blocks are definitely lost in loss record 7 of 251
==68902==    at 0x4843828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==68902==    by 0x5225948: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1)
==68902==    by 0x5240ED2: g_strdup (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1)
==68902==    by 0x13135E: g_strdup_inline (gstrfuncs.h:321)
==68902==    by 0x13135E: dom_tree_to_text(_xmlNode*) (sixtp-dom-parsers.cpp:500)
==68902==    by 0x141758: test_bad_string() (test-string-converters.cpp:70)
==68902==    by 0x1417D8: main (test-string-converters.cpp:82)
==68902==
==68902== 93 bytes in 5 blocks are definitely lost in loss record 199 of 251
==68902==    at 0x4843828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==68902==    by 0x5225948: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1)
==68902==    by 0x5240ED2: g_strdup (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1)
==68902==    by 0x13135E: g_strdup_inline (gstrfuncs.h:321)
==68902==    by 0x13135E: dom_tree_to_text(_xmlNode*) (sixtp-dom-parsers.cpp:500)
==68902==    by 0x14169B: test_string_converters() (test-string-converters.cpp:55)
==68902==    by 0x1417D3: main (test-string-converters.cpp:81)
==68902==
==68902== 260 (120 direct, 140 indirect) bytes in 1 blocks are definitely lost in loss record 242 of 251
==68902==    at 0x4843828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==68902==    by 0x48D5B84: xmlNewNode (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.14)
==68902==    by 0x133873: text_to_dom_tree(char const*, char const*) (sixtp-dom-generators.cpp:53)
==68902==    by 0x141748: test_bad_string() (test-string-converters.cpp:68)
==68902==    by 0x1417D8: main (test-string-converters.cpp:82)
==68902==
==68902== 1,353 (600 direct, 753 indirect) bytes in 5 blocks are definitely lost in loss record 248 of 251
==68902==    at 0x4843828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==68902==    by 0x48D5B84: xmlNewNode (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.14)
==68902==    by 0x133873: text_to_dom_tree(char const*, char const*) (sixtp-dom-generators.cpp:53)
==68902==    by 0x14168B: test_string_converters() (test-string-converters.cpp:54)
==68902==    by 0x1417D3: main (test-string-converters.cpp:81)
==68902==
2023-07-19 10:21:30 +01:00
John Ralls
741ce55b7a Merge Richard Cohen's 'use-g-assert-true-in-tests' into stable. 2023-07-16 10:13:26 -07:00
Richard Cohen
66c5e398ae Change g_assert() -> g_assert_true() in tests
g_assert() can be compiled out, so should not be used for tests

g_assert_true was removed
to fis https://bugs.gnucash.org/show_bug.cgi?id=792008 because
g_assert_true was introduced in glib-2.38 and at the time GnuCash required
only glib-2.26. GnuCash has required glib >= 2.40 since 8acbc41c6 so
g_assert_true can be restored.
2023-07-16 10:09:12 -07:00
John Ralls
f2d9230299 Improve error reporting on DBI large number test failures.
There are other reasons than the original bug that can cause failure,
get some more information to understand what's going on.
2023-07-10 13:25:10 -07:00
Christopher Lam
b011c81b62 [gnc-backend-dbi.cpp] if returning early, don't allocate char*
this function may return early causing leak from allocating
g_build_filename.
2023-07-02 21:46:29 +08:00
Christopher Lam
0d326fa100 [io-gncxml-v2.cpp] plug g_strdup leak 2023-07-01 11:59:40 +08:00
Vincent Dawans
e0e13604b5 Bug 798967 - Cannot Save to Any Path After Upgrading to 5.2
Fix inverted if statement condition for save success flag
2023-06-25 18:50:58 -07:00
Simon Arlott
d7b2b06bae
Avoid unnecessary memory allocation in dom_tree_to_gnc_numeric()
Return a gnc_numeric instead of allocations that every caller has to free.

This makes it easier to fix the use after free in the unit test function
equals_node_val_vs_split_internal() where the expression in the return
statement wants to use the allocated gnc_numeric.
2023-06-24 20:30:42 +01:00
Simon Arlott
4b83068c6b
Fix return value of gnc_book_write_to_xml_file_v2()
81b9a02235 changed the behaviour of the
"success" variable that's used for the return value, so now the value is
being repeatedly overwritten instead of being combined with the result of
the next call.

Restore the original behaviour of setting success to false on failure.
2023-06-24 16:46:44 +01:00
Richard Cohen
2e861ab673 Valgrind: fix "Mismatched free/delete" - test-dom-converters1
==32195== Mismatched free() / delete / delete []
==32195==    at 0x484620F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==32195==    by 0x146DB5: test_dom_tree_to_guid() (test-dom-converters1.cpp:251)
...
==32195==  Address 0x8043780 is 0 bytes inside a block of size 16 alloc'd
==32195==    at 0x4843FA3: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==32195==    by 0x503E06E: guid_malloc (guid.cpp:106)
==32195==    by 0x503E0D5: guid_copy (guid.cpp:123)
==32195==    by 0x503E1E7: guid_new (guid.cpp:154)
==32195==    by 0x147188: get_random_guid (test-engine-stuff.cpp:207)
==32195==    by 0x146D03: test_dom_tree_to_guid() (test-dom-converters1.cpp:237)
...
2023-06-19 13:53:24 +01:00
Richard Cohen
3abc9a5558 Refactor: Remove some unnecessary uses of memcpy
- Also, remove unnecessary "static" in gnucash-style.c

The second one in guid.cpp is UB:

libgnucash/engine/guid.cpp:137:5: warning: undefined behavior, source object type 'const gnc::GUID' is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
        memcpy (&target, &source, sizeof (GncGUID));
        ^
2023-06-15 11:10:58 +01:00
John Ralls
26162da450 Merge Richard Cohen's 'cleanup-build' into stable. 2023-05-17 21:16:09 -05:00
Richard Cohen
3c34a61776 Remove #pragma ... "-Wformat-nonliteral"
Seems to have been accidentally left behind when time64_to_string()
was (re)moved
2023-05-15 13:21:30 +01:00
Richard Cohen
1f43bbc798 Remove #pragma ..."-Wstrict-aliasing"
G_LOCK was fixed in glib 2.19.8

See https://bugzilla.gnome.org/show_bug.cgi?id=316221
2023-05-15 13:21:30 +01:00
Richard Cohen
80e9d9c35d scanf supports %lld since C++11, C99 2023-05-15 13:21:30 +01:00
Richard Cohen
7f1ce2b5e5 Remove references to cutecash 2023-05-15 13:21:29 +01:00
Richard Cohen
3957272ef0 Fix some typos in comments 2023-05-13 13:00:25 +01:00
John Ralls
df878c6a3d Merge Maarten Bosmans's 'memleak-fixes' into stable. 2023-04-29 11:54:41 -07:00
Maarten Bosmans
6be682b645 Store allocated temporaries in a variable so they can be freed
If a function that returns an allocated pointer is passed directly into
something that does not take ownership of the pointer, the allocation is
leaked.  This can be fixed by assigning the pointer to a new variable
and freeing it after operation on the memory.
2023-04-29 11:51:43 -07:00
Robert Fewell
fb58959f9a Bug 798885 - Accented character in folder name on Account Export
Changed export_coa to use g_fopen instead of fopen
2023-04-28 09:55:57 +01:00
Maarten Bosmans
bd94965d9b [backend/xml] Remove unused string copy 2023-04-02 21:12:50 +02:00
Richard Cohen
6ba5bb326a Fix dereference of expired temporaries.
Reported by clang 15.0.7, which will be in Ubuntu 23.04, -Wdangling-gsl
2023-03-31 11:27:33 -07:00
Richard Cohen
30586ac3e6 Push -Wno-error=deprecated-declarations from C*_FLAGS down to the target 2023-03-15 10:34:14 +00:00
Richard Cohen
3a7464a312 Remove redundant uses of cmake -E env
- In GncAddTest, set_tests_properties() is already setting the env
- In the other uses, there is no change to the environment
2023-03-07 15:44:43 +00:00