summaryrefslogtreecommitdiff
path: root/glib
Commit message (Collapse)AuthorAgeFilesLines
* GString: Support on-stack useg-string-on-stackMatthias Clasen2023-01-173-15/+147
| | | | | | Move the preallocation into the GString struct, and add g_string_init and g_string_clear to enable on-stack use of GString.
* tests: Fix unsafe use of GStringMatthias Clasen2023-01-171-5/+2
|
* keyfile: Fix unsafe use of GStringMatthias Clasen2023-01-171-4/+1
|
* Merge branch 'issue_2883b' into 'main'Philip Withnall2023-01-161-2/+7
|\ | | | | | | | | | | | | Use 'write' with 'count' <= max value of its return type Closes #2883 See merge request GNOME/glib!3200
| * gfileutils: Use 'write' with 'count' <= max value of its return typeCCode2023-01-161-2/+7
| | | | | | | | | | | | | | | | | | | | Limit `count` so that `write` can properly report the number of written bytes. Limits: - POSIX: `SSIZE_MAX` - Windows: `INT_MAX` Fixes: #2883
* | Merge branch 'gstring-optimizations' into 'main'Philip Withnall2023-01-164-40/+108
|\ \ | |/ |/| | | | | Some GString optimizations See merge request GNOME/glib!3199
| * Try to make gtk-doc happyMatthias Clasen2023-01-141-1/+6
| |
| * markup: Use g_string_truncateMatthias Clasen2023-01-141-9/+2
| | | | | | | | | | We don't need a private inline helper for this anymore.
| * markup: Replace a g_string_insert_len callMatthias Clasen2023-01-141-1/+1
| | | | | | | | This lets us use the optimized inline call.
| * Improve the g_string_truncate testMatthias Clasen2023-01-141-1/+1
| | | | | | | | Test the inline version too.
| * string: Add an inline g_string_truncate tooMatthias Clasen2023-01-142-2/+14
| | | | | | | | | | This is another very commonly used GString function.
| * Improve the g_string_append testMatthias Clasen2023-01-141-3/+21
| | | | | | | | | | Test the inline versions too, and test passing -1 for len.
| * Improve the g_string_append_c testMatthias Clasen2023-01-141-2/+5
| | | | | | | | We should check the resulting string too.
| * string: Optimize g_string_append(_len)Matthias Clasen2023-01-142-8/+38
| | | | | | | | | | | | Add static inline versions of these functions that boil down to just an memcpy. ag_string_append_len is used quite a bit in GMarkup and GTK's css parser.
| * string: Add a G_LIKELYMatthias Clasen2023-01-141-1/+1
| | | | | | | | This is the case we optimize for.
| * string: Split g_string_maybe_expandMatthias Clasen2023-01-141-12/+19
| | | | | | | | | | Split off g_string_expand, and inline just the size check.
* | Merge branch 'regex-invalid-memory-access' into 'main'Marco Trevisan2023-01-122-2/+36
|\ \ | |/ |/| | | | | | | | | gregex: Prevent invalid memory access for unmatched subpatterns Closes #2881 See merge request GNOME/glib!3194
| * gregex: Prevent invalid memory access for unmatched subpatternsPhilip Withnall2023-01-112-2/+36
| | | | | | | | | | | | | | | | Based on a test by Emmanuel Pacaud. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Fixes: #2881
* | Merge branch 'badcel/revert-update-closure-annotations' into 'main'Philip Withnall2023-01-1115-35/+35
|\ \ | |/ |/| | | | | | | | | Revert "Rename user data parameters to user_data" Closes #2827 See merge request GNOME/glib!3111
| * Do not name callback parameters "user_data"badcel2023-01-091-2/+2
| | | | | | | | Calling a callback parameter "user_data" implicitly adds the "closure" attribute in the documentation which is wrong for callbacks.
| * Revert "Rename all user datas in callbacks to user_data"badcel2023-01-093-13/+13
| | | | | | | | This reverts commit 1422e5f81241650c634413911e92d23495692545. The renaming of parameters implicitly introduced "closure" annotations in the documentation which are wrong on callbacks.
| * Revert "Rename user data parameters to user_data"badcel2023-01-0913-20/+20
| | | | | | | | This reverts commit da7a31a052614edd2cc87518585ff371cbb0f204. The renaming of parameters implicitly introduced "closure" annotations in the documentation which are wrong on callbacks.
* | Merge branch 'wip/smcv/gptrarray-null-term' into 'main'Simon McVittie2023-01-101-0/+3
|\ \ | | | | | | | | | | | | | | | | | | garray: Update NULL termination after copying array content Closes #2877 See merge request GNOME/glib!3190
| * | garray: Update NULL termination after copying array contentSimon McVittie2023-01-101-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ptr_array_new(len, ., TRUE) ensures that there are at least len+1 elements in pdata, and that pdata[0] is null, but leaves the rest of pdata uninitialized. After copying the array data into pdata[1] to pdata[len-1] inclusive, we still need to make sure pdata[len] is a null terminator. Note that if len is 0, then pdata is not guaranteed to be non-null. If it's null, then we can't add null-termination to it until its size is updated. Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2877 Signed-off-by: Simon McVittie <smcv@collabora.com>
* | | Merge branch 'wip/smcv/rlimit-nproc-error' into 'main'Simon McVittie2023-01-101-1/+2
|\ \ \ | | | | | | | | | | | | | | | | tests: Improve error message if setting max processes to 1 fails See merge request GNOME/glib!3191
| * | | tests: Improve error message if setting max processes to 1 failsSimon McVittie2023-01-101-1/+2
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This has historically failed on Debian autobuilders, and as a result we have had a patch for a long time that turned a failure here into a g_test_skip(). It's not clear whether this still happens, so I'm now assessing whether the patch can be dropped; but if the prlimit() call can fail for whatever reason, it would be useful for the error message to say what limit we were trying to set. Signed-off-by: Simon McVittie <smcv@collabora.com>
* | | Merge branch 'wip/smcv/gptrarray-memcpy-nothing' into 'main'Simon McVittie2023-01-101-1/+1
|\ \ \ | | | | | | | | | | | | | | | | garray: Avoid calling memcpy with no items See merge request GNOME/glib!3192
| * | | garray: Avoid calling memcpy with no itemsSimon McVittie2023-01-101-1/+1
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | `memcpy(NULL, ., n)` and `memcpy(., NULL, n)` are undefined behaviour, even if *n* is zero. When len is 0 here, callers are allowed to pass in null data, and GPtrArray also does not guarantee to have allocated rarray->pdata yet. Signed-off-by: Simon McVittie <smcv@collabora.com>
* | | docs: Fix return type in cmpint exampleCédric Bellegarde2023-01-101-1/+1
|/ /
* | build: Don't overwrite build variablesEmmanuele Bassi2023-01-081-2/+2
|/ | | | | | | We cannot use `gvisibility_h` for different visibility header files; you never know when you're going to refer to the variable again, and projects might end up needing to retrieve the variable contents—like, for instance, gobject-introspection using glib as a subproject.
* Merge branch '2871-find-program-for-path-leak' into 'main'Emmanuele Bassi2023-01-061-6/+13
|\ | | | | | | | | | | | | gutils: Avoid possible leaks in g_find_program_for_path() Closes #2871 See merge request GNOME/glib!3183
| * gutils: Avoid possible leaks in g_find_program_for_path()Philip Withnall2023-01-051-6/+13
| | | | | | | | | | | | Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Fixes: #2871
* | Merge branch 'ptr-array-sort-values' into 'main'Philip Withnall2023-01-063-4/+305
|\ \ | |/ |/| | | | | garray: Add g_ptr_array_sort_values[_with_data]() wrappers See merge request GNOME/glib!3155
| * garray: Add g_ptr_array_sort_values[_with_data]() wrappersMarco Trevisan (Treviño)2023-01-063-4/+305
| | | | | | | | | | | | | | | | | | | | Historically GPtrArray made possible to compare pointers of pointers values that it holds, however this is inconvenient in most cases as it requires wrapper functions and not friendly castings. So, add two functions that allow to perform the comparisons between the pointer values that a GPtrArray holds following the same syntax that we share everywhere in the codebase.
* | gstrfuncs: Fix grammar in documentation of stpcpyPeter Bloomfield2023-01-021-5/+5
| | | | | | | | Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2857
* | garray: Add some additional length assertionsPhilip Withnall2022-12-291-0/+2
| | | | | | | | | | | | | | | | This should shut Coverity up. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Coverity CID: #1502194
* | gvariant: Propagate trust when getting a child of a serialised variantPhilip Withnall2022-12-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a variant is trusted, that means all its children are trusted, so ensure that their checked offsets are set as such. This allows a lot of the offset table checks to be avoided when getting children from trusted serialised tuples, which speeds things up. No unit test is included because this is just a performance fix. If there are other slownesses, or regressions, in serialised `GVariant` performance, the fuzzing setup will catch them like it did this one. This change does reduce the time to run the oss-fuzz reproducer from 80s to about 0.7s on my machine. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Fixes: #2841 oss-fuzz#54314
* | gvariant: Check offset table doesn’t fall outside variant boundsPhilip Withnall2022-12-212-3/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When dereferencing the first entry in the offset table for a tuple, check that it doesn’t fall outside the bounds of the variant first. This prevents an out-of-bounds read from some non-normal tuples. This bug was introduced in commit 73d0aa81c2575a5c9ae77d. Includes a unit test, although the test will likely only catch the original bug if run with asan enabled. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Fixes: #2840 oss-fuzz#54302
* | Merge branch 'ptr-array-new-take' into 'main'Philip Withnall2022-12-213-2/+1205
|\ \ | | | | | | | | | | | | garray: Add more G(Ptr)Array constructors to take or copy C arrays See merge request GNOME/glib!3128
| * | garray: Fix a doc typo in g_ptr_array_sort()Marco Trevisan (Treviño)2022-12-211-1/+1
| | |
| * | garray: Add g_array_new_take() and g_array_new_take_zero_terminated()Marco Trevisan (Treviño)2022-12-213-0/+317
| | | | | | | | | | | | | | | Make it easy to handle C arrays using GArray API stealing data from other sources.
| * | garray: Just use one bit to hold the null teminated stateMarco Trevisan (Treviño)2022-12-191-1/+1
| | | | | | | | | | | | | | | This is probably ignored for saving space because of padding optimizations, but since we want this value to be either 0 or 1, this enforces this too.
| * | garray: Add g_ptr_array_new_from_null_terminated_array()Marco Trevisan (Treviño)2022-12-193-14/+271
| | | | | | | | | | | | | | | | | | It allows to create a GPtrArray from a null-terminated C array computing its size and in case performing copies of the its values using the provided GCopyFunc.
| * | garray: Add g_ptr_array_new_from_array() to copy a C arrayMarco Trevisan (Treviño)2022-12-193-1/+213
| | | | | | | | | | | | | | | It makes it easier (and more optimized) to create a GPtrArray from a C-style array of pointers, in case using a GCopyFunc to duplicate the elements.
| * | garray: Add g_ptr_array_new_take_null_terminated()Marco Trevisan (Treviño)2022-12-193-0/+221
| | | | | | | | | | | | | | | Similar to g_ptr_array_new_take() but it also computes the length of a zero-terminated array.
| * | garray: Add g_ptr_array_new_take() to take a C array without copiesMarco Trevisan (Treviño)2022-12-193-0/+196
| | | | | | | | | | | | | | | | | | | | | | | | | | | GPtrArray is a nice interface to handle pointer arrays, however if a classic array needs to be converted into a GPtrArray is currently needed to manually go through all its elements and do new allocations that could be avoided. So add g_ptr_array_new_take() which steals the data from an array of pointers and allows to manage it using the GPtrArray API.
* | | gmain: Define fallback values for siginfo_t constants for muslPhilip Withnall2022-12-211-8/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | musl doesn’t define them itself, presumably because they’re not defined in POSIX. glibc does define them. Thankfully, the values used in glibc match the values used internally in other musl macros. Define the values as a fallback. As a result of this, we can get rid of the `g_assert_if_reached()` checks in `siginfo_t_to_wait_status()`. This should fix catching signals from a subprocess when built against musl. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Fixes: #2852
* | | Merge branch '2753-vasprintf-loop' into 'main'Philip Withnall2022-12-213-0/+208
|\ \ \ | | | | | | | | | | | | | | | | glib/tests: Add test to check that we abort on low-memory See merge request GNOME/glib!2992
| * | | glib/tests: Add test to check that we abort on low-memoryMarco Trevisan (Treviño)2022-12-203-0/+208
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In case we're out of memory we should abort after having printed an error message, this is similar to crashing but not exactly the same, so ensure we exit for SIGABRT and not because of a SIGSEV. We use a test wrapper to ensure that both the exit code and the stderr match what we expected.
* | | | gthread-posix: need to #include <errno.h>Michael Catanzaro2022-12-201-0/+1
| | | | | | | | | | | | | | | | | | | | a79c6af23eff5ee978db62e048828c9a992a1261 uses errno without the required header.