Commit Graph

7644 Commits

Author SHA1 Message Date
Loic Le Page
fb939a0029 Fix redefinition of local variable in glib/tests/sequence.c 2022-02-21 12:42:22 +01:00
Loic Le Page
5804fa1680 Fix global variable name hidden by local variables in glib/tests/spawn-multithreaded.c 2022-02-21 12:42:22 +01:00
Loic Le Page
22b7182d2a Fix redefinition of local variable in glib/tests/strfuncs.c 2022-02-21 12:42:15 +01:00
Loïc Le Page
cbc3d65f6d Fix global variable name hidden by local variables in glib/tests/utf8-validate.c 2022-02-21 12:38:11 +01:00
Philip Withnall
ae903744ee Merge branch 'environment-test-fixes' into 'main'
tests: Fix various small memory leaks

See merge request GNOME/glib!2509
2022-02-20 12:09:00 +00:00
Philip Withnall
9ee583a387 gmain: Expand documentation about GSource priorities a little
Prompted by https://stackoverflow.com/q/71173668/2931197

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-20 11:44:09 +00:00
Philip Withnall
2bc1036f80 tests: Fix a memory leak in the mainloop test
The source needs to be removed from the `GMainContext` before being
unreffed, otherwise the main context and main loop will be kept around.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-20 10:43:26 +00:00
Philip Withnall
ba556e6d34 tests: Fix a memory leak in the keyfile test
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-20 10:43:26 +00:00
Philip Withnall
a389227fb9 tests: Fix a memory leak in the fileutils test
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-20 10:43:26 +00:00
Philip Withnall
12a4fcdbed tests: Fix a leak in environment.c with undefined behaviour tests on
`g_environ_setenv()` and `g_environ_unsetenv()` were correctly returning
`NULL` when their preconditions failed (as the test is supposed to be
exercising). That overwrote the value of `env` without freeing it,
resulting in a leak.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-20 10:43:26 +00:00
Philip Withnall
cb18e6b969 Merge branch 'empty-argv' into 'main'
Various minor fixes for empty argv handling

See merge request GNOME/glib!2466
2022-02-20 09:36:41 +00:00
Philip Withnall
a57c33fc1d Merge branch 'cleanup-warnings-split-3' into 'main'
Cleanup warnings split 3

See merge request GNOME/glib!2492
2022-02-18 13:45:42 +00:00
Philip Withnall
5ac86e21b3 Merge branch 'cleanup-warnings-split-2' into 'main'
Cleanup warnings split 2

See merge request GNOME/glib!2491
2022-02-18 13:39:25 +00:00
Philip Withnall
e80569bd86 Merge branch 'iochannel-test' into 'main'
tests: Merge iochannel-test into io-channel tests in glib directory

See merge request GNOME/glib!2502
2022-02-18 10:39:43 +00:00
Philip Withnall
2249da981a tests: Use g_assert_*() rather than g_assert() in environment.c
`g_assert()` is compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-18 10:18:40 +00:00
Loic Le Page
800457e102 Fix non-initialized variable in glib/garray.c 2022-02-18 10:59:30 +01:00
Loic Le Page
112ad3d591 Fix too small array definition in glib/gconvert.c (no room for the '\0') 2022-02-18 10:59:30 +01:00
Loic Le Page
d5580edfa7 Fix non-initialized variable in glib/gdatetime.c 2022-02-18 10:59:30 +01:00
Loic Le Page
7304e4de17 Fix non-initialized variable in glib/giowin32.c 2022-02-18 10:59:30 +01:00
Loic Le Page
c118fd5e37 Fix non-initialized variable in glib/gmarkup.c 2022-02-18 10:59:30 +01:00
Loic Le Page
51e54f64c1 Fix global variable name hidden by local variables in glib/gslice.c 2022-02-18 10:53:35 +01:00
Loic Le Page
eaf37d63d0 Fix non-initialized variable in glib/gspawn-win32.c 2022-02-18 10:53:35 +01:00
Loic Le Page
499cb2cd1a Fix non-initialized variable and signed/unsigned mismatch in glib/gtimezone.c 2022-02-18 10:53:35 +01:00
Loic Le Page
e8761bb4df Fix non-initialized variable and signed/unsigned mismatch in glib/gunicollate.c 2022-02-18 10:53:35 +01:00
Loic Le Page
eb961b02d6 Fix too small array definition in glib/guri.c (no room for the '\0') 2022-02-18 10:52:39 +01:00
Loic Le Page
bdf1a0ba80 Fix non-initialized variable in glib/gutils.c 2022-02-18 10:52:39 +01:00
Loic Le Page
28fa4325a4 Fix non-initialized variable in glib/gvariant-parser.c 2022-02-18 10:52:38 +01:00
Loic Le Page
de8ab33cb5 Fix global variable name hidden by local variables in glib/gwin32-private.c 2022-02-18 10:52:38 +01:00
Philip Withnall
0694c1a5ad gbacktrace: Fix a set-but-not-used variable
It’s only used if building for lldb. Spotted in the log from an oss-fuzz
build:
https://oss-fuzz-build-logs.storage.googleapis.com/log-051f05da-adf5-42c1-8f14-5e36ba750573.txt:
```
Step #12 - "compile-honggfuzz-address-x86_64": [36/1232] Compiling C object glib/libglib-2.0.a.p/gbacktrace.c.o
Step #12 - "compile-honggfuzz-address-x86_64": ../../src/glib/glib/gbacktrace.c:324:24: warning: variable 'line_idx' set but not used [-Wunused-but-set-variable]
Step #12 - "compile-honggfuzz-address-x86_64":   int sel, idx, state, line_idx;
Step #12 - "compile-honggfuzz-address-x86_64":                        ^
Step #12 - "compile-honggfuzz-address-x86_64": 1 warning generated.
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-17 21:46:39 +00:00
Philip Withnall
5b7383c544 tests: Merge iochannel-test into io-channel tests in glib directory
We’re trying to eliminate the legacy `tests/` directory. This commit
moves the code from `tests/iochannel-test.c` into
`glib/tests/io-channel.c` and ports it to the latest GLib test coding
standards:
 * Change `g_assert()` to `g_assert_*()`
 * Print verbose messages with `g_test_message()`
 * Rename some variables to conform to modern conventions
 * Use `GTest`

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1434
2022-02-17 21:42:35 +00:00
Marc-André Lureau
4549a97a75 glib/tests: ucrt locale date output is a bit different
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-02-15 23:21:49 +00:00
Marc-André Lureau
f7c66423a4 glib/tests: set Polish ThreadLocale on win32 to fix a test
Fixes /date/month_substring
Bail out! GLib:ERROR:../glib/tests/date.c:1090:test_month_substring: 'g_date_valid (&date)' should be TRUE

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-02-15 23:21:49 +00:00
Marc-André Lureau
051d000acd glib/tests: fix checking two-digit years on Windows
Fixes:
ok 10 /date/parse_locale_change

(when locale th_TH available)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-02-15 23:21:49 +00:00
Marc-André Lureau
acb46f8b36 glib/tests: add comment about %Z strftime on w32
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-02-16 03:00:06 +04:00
Philip Withnall
00ba3ceacc Merge branch 'wip/smcv/aligned-alloc-tests' into 'main'
Fix some problems with g_aligned_alloc() tests

See merge request GNOME/glib!2488
2022-02-15 11:52:46 +00:00
Philip Withnall
27798cda22 Merge branch 'fix_gdate_tests' into 'main'
Fix unit test on date format '%Z' which is too versatile to be trustable

See merge request GNOME/glib!2482
2022-02-15 11:46:59 +00:00
Simon McVittie
b0f686a00e tests: Don't test invalid aligned allocations if avoiding UB
We can't exercise precondition check failures if GLib was (inadvisably)
compiled with -Dglib_checks=false, and we shouldn't necessarily exercise
precondition check failures when using QA tools like valgrind, so skip
these tests if run with -m no-undefined.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-02-15 11:03:00 +00:00
Simon McVittie
38cdfe3c02 tests: Make g_aligned_alloc tests fail if preconditions aren't checked
Previously, these tests would always pass. If the precondition check
failed (as we want it to), the subprocess would exit unsuccessfully;
but if the precondition check wrongly passed, the subprocess would
continue, allocate a nonzero amount of memory, and fail the
g_assert_null(), resulting in the subprocess exiting unsuccessfully
and the test still passing.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-02-15 10:52:59 +00:00
Simon McVittie
d04f3491af tests: Don't assume that all platforms are 64-bit
On ILP32 platforms, 4 is a valid alignment for g_aligned_alloc(), so
use 2 as our invalid alignment instead.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-02-15 10:49:51 +00:00
Emmanuel Fleury
81764b6508 Fix unit test on date format '%Z' which is too versatile to be trustable 2022-02-15 11:43:25 +01:00
Chun-wei Fan
87db363501 gconstructor.h: Visual Studio: Only include gslist.h if needed
We only want to include gslist.h here if it was not already included via
including glib.h, as:

* gslist.h should normally be included via glib.h if used outside of
  GLib itself.
* This broke Visual Studio builds that use GResources (via
  glib-compile-resources.exe) as that would cause the generated code to
  include gslist.h directly, which is therefore disallowed.
2022-02-14 18:35:58 +08:00
Philip Withnall
f9c08308ea Merge branch 'ebassi/aligned-alloc' into 'main'
Add aligned memory allocators

Closes #2574

See merge request GNOME/glib!2421
2022-02-11 15:04:25 +00:00
Philip Withnall
a6311f81ee gtestutils: Handle empty argv array passed to g_test_init()
This can happen if a caller (ab)uses `execve()` to execute a gtest
process with an empty `argv` array. `g_test_init()` has to gracefully
handle such a situation.

Fix a few problem areas in the code, and add a simple test which checks
that `g_test_init()` doesn’t crash when called with an empty `argv`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-11 14:47:19 +00:00
Philip Withnall
44f4d55150 gspawn: Clarify that empty argv arrays are not allowed when spawning
While `execve()` might allow (probably malicious) users to execute a
program with an empty `argv` array, gspawn does not. It’s not actually
possible, as the path to the binary to execute is not specified
separately from the argument array.

Explicitly document and encode that in preconditions.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-11 14:45:43 +00:00
Philip Withnall
18fc711355 gshell: Mention handling of empty argv arrays in the documentation
It is not possible for `g_shell_parse_argv()` to return an empty `argv`
array. Make that clear in the documentation and add some assertions to
encode it explicitly in the code.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-11 14:45:43 +00:00
Philip Withnall
3ea4ba31a1 tools: Fix handling of empty argv in various minor GLib tools
This won’t really affect anything, but we might as well fix them to not
crash if called with an empty `argv` by someone (ab)using `execve()`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-11 14:45:42 +00:00
Emmanuele Bassi
36449ef5f9 Explain the errno use in g_aligned_alloc() 2022-02-11 14:44:09 +00:00
Emmanuele Bassi
b37c99c44e Add tests for g_aligned_alloc()
We want to test the API contract, by checking the return value for
zero-sized allocations, invalid alignments, and overflows.
2022-02-11 14:44:09 +00:00
Emmanuele Bassi
475d574440 Add aligned memory allocators
When working with storage (especially GInputStream or GOutputStream) it
is preferred to use page-aligned buffers so that the operating system
can do page-mapping tricks as the operation passes through the kernel.

Another use case is allocating memory used for vectorised operations,
which must be aligned to specific boundaries.

POSIX and Windows, as well as the C11 specification, provide this kind
of allocator functions, and GLib already makes use of it inside GSlice.
It would be convenient to have a public, portable wrapper that other
projects can use.

Fixes: #2574
2022-02-11 14:44:09 +00:00
Philip Withnall
1094bfc7d7 Merge branch 'wip/smcv/defer-test-cleanup' into 'main'
testutils: Defer global cleanup until we really exit

Closes #2563

See merge request GNOME/glib!2420
2022-02-11 14:21:43 +00:00