If a path starts with more than two slashes, the `start` value was
previously incorrect:
1. As per the `g_path_skip_root()` call, `start` was set to point to
after the final initial slash. For a path with three initial
slashes, this is the character after the third slash.
2. The canonicalisation loop to find the first dir separator sets
`output` to point to the character after the first slash (and it
overwrites the first slash to be `G_DIR_SEPARATOR`).
3. At this point, with a string `///usr`, `output` points to the second
`/`; and `start` points to the `u`. This is incorrect, as `start`
should point to the starting character for output, as per the
original call to `g_path_skip_root()`.
4. For paths which subsequently include a `..`, this results in the
`output > start` check in the `..` loop below not skipping all the
characters of a preceding path component, which is then caught by
the `G_IS_DIR_SEPARATOR (output[-1])` assertion.
Fix this by resetting `start` to `output` after finding the final slash
to keep in the output, but before starting the main parsing loop.
Relatedly, split `start` into two variables: `after_root` and
`output_start`, since the variable actually has two roles in the two
parts of the function.
Includes a test.
This commit is heavily based on suggestions by Sebastian Wilhemi and
Sebastian Dröge.
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
oss-fuzz#41563
Previously tests existed in two places,
`$top_srcdir/tests/sources.c` contained additional tests,
they have now been moved to `$top_srcdir/glib/tests/mainloop.c`
and `$top_srcdir/tests/sources.c` was deleted.
Related to: #1434
Previously tests existed in two places,
`$top_srcdir/tests/qsort-test.c` contained a similar test
to the one in `$top_srcdir/glib/tests/sort.c` called `test_sort_basic()`
The test for checking with zero elements was additional added to
`$top_srcdir/glib/tests/sort.c` and `$top_srcdir/tests/qsort-test.c`
was deleted.
Related to: #1434
Improve the performance of canonicalising filenames with many `..` or
`.` components, by modifying the path inline rather than calling
`memmove()`.
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Fixes: #2541
Port all existing calls in GLib to the new API so that they can receive
more detailed error information (although none of them actually make use
of it at the moment).
This also serves to test the new API better through use.
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: #203
No behavior changes. Just reindent the existing code to avoid a GCC
warning spam.
I considered changing the code to not run fflush() on every iteration of
the loop, but I doubt it matters much, so I left it be.
gjs has some situations where it's not always aware of the @data that
was passed into g_object_add_toggle_ref, so allow passing %NULL to
just match on @notify.
Rebased and updated by Nitin Wartkar
Closes#817
tests/unicode-collate.c: In function ‘main’:
tests/unicode-collate.c:77:11: error: comparison of integer expressions of different signedness: ‘int’ and ‘guint’ {aka ‘unsigned int’}
77 | if (argc > i)
| ^
tests/timeloop.c: In function ‘read_all’:
tests/timeloop.c:41:21: error: comparison of integer expressions of different signedness: ‘gsize’ {aka ‘long unsigned int’} and ‘int’
41 | while (bytes_read < len)
| ^
tests/timeloop.c: In function ‘write_all’:
tests/timeloop.c:65:24: error: comparison of integer expressions of different signedness: ‘gsize’ {aka ‘long unsigned int’} and ‘int’
65 | while (bytes_written < len)
| ^
tests/slice-threadinit.c: In function ‘main’:
tests/slice-threadinit.c:77:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
77 | for (j = 0; j < N_MAGAZINE_PROBES; j++)
| ^
tests/slice-threadinit.c:108:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
108 | for (j = 0; j < N_MAGAZINE_PROBES; j++)
| ^
tests/slice-threadinit.c:113:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
113 | for (j = 0; j < N_MAGAZINE_PROBES; j++)
| ^
tests/slice-threadinit.c:131:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
131 | for (j = 0; j < N_MAGAZINE_PROBES; j++)
| ^
tests/slice-threadinit.c:139:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
139 | for (j = 0; j < N_MAGAZINE_PROBES; j++)
| ^
tests/slice-threadinit.c:161:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
161 | for (j = 0; j < N_MAGAZINE_PROBES; j++)
| ^
I did it wrong last time... my bad...
tests/gobject/performance-threaded.c: In function ‘main’:
tests/gobject/performance-threaded.c:361:21: warning: comparison of integer expressions of different signedness: ‘gsize’ {aka ‘long unsigned int’} and ‘int’
361 | for (k = 1; k < argc; k++)
| ^
tests/mainloop-test.c: In function ‘cleanup_crawlers’:
tests/mainloop-test.c:358:15: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
358 | for (i=0; i < crawler_array->len; i++)
| ^
tests/dirname-test.c: In function ‘main’:
tests/dirname-test.c:105:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
105 | for (i = 0; i < n_dirname_checks; i++)
| ^
tests/gobject/performance-threaded.c: In function ‘run_test’:
tests/gobject/performance-threaded.c:302:19: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘int’
302 | for (i = 0; i < n_threads; i++) {
| ^
tests/gobject/performance-threaded.c:308:19: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘int’
308 | for (i = 0; i < n_threads; i++) {
| ^
tests/gobject/performance-threaded.c: In function ‘find_test’:
tests/gobject/performance-threaded.c:324:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
324 | for (i = 0; i < G_N_ELEMENTS (tests); i++)
| ^
tests/gobject/performance-threaded.c: In function ‘main’:
tests/gobject/performance-threaded.c:351:21: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
351 | for (i = 0; i < G_N_ELEMENTS (tests); i++)
| ^
tests/gobject/performance-threaded.c:369:21: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
369 | for (i = 0; i < G_N_ELEMENTS (tests); i++)
| ^
tests/gobject/timeloop-closure.c: In function ‘read_all’:
tests/gobject/timeloop-closure.c:42:21: error: comparison of integer expressions of different signedness: ‘gsize’ {aka ‘long unsigned int’} and ‘int’
42 | while (bytes_read < len)
| ^
tests/gobject/timeloop-closure.c: In function ‘write_all’:
tests/gobject/timeloop-closure.c:66:24: error: comparison of integer expressions of different signedness: ‘gsize’ {aka ‘long unsigned int’} and ‘int’
66 | while (bytes_written < len)
| ^
tests/refcount/objects.c: In function ‘main’:
tests/refcount/objects.c:133:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘const unsigned int’}
133 | for (i = 0; i < n_threads; i++) {
| ^
tests/refcount/objects.c:149:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘unsigned int’
149 | for (i = 0; i < 2 * n_threads; i++) {
| ^
tests/gobject/performance.c: In function ‘find_test’:
tests/gobject/performance.c:1019:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
1019 | for (i = 0; i < G_N_ELEMENTS (tests); i++)
| ^
tests/gobject/performance.c: In function ‘main’:
tests/gobject/performance.c:1054:21: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
1054 | for (i = 0; i < G_N_ELEMENTS (tests); i++)
| ^
tests/onceinit.c: In function ‘stress_concurrent_initializers’:
tests/onceinit.c:267:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
267 | for (i = 0; i < G_N_ELEMENTS (initializers); i++)
| ^
tests/gobject/defaultiface.c: In function ‘test_dynamic_iface_register’:
tests/gobject/defaultiface.c:126:5: error: missing initializer for field ‘class_data’ of ‘GTypeInfo’ {aka ‘const struct _GTypeInfo’}
126 | };
| ^
tests/gobject/testmodule.c: In function ‘test_module_get_type’:
tests/gobject/testmodule.c:34:1: error: missing initializer for field ‘value_table’ of ‘GTypeInfo’ {aka ‘const struct _GTypeInfo’}
34 | DEFINE_TYPE (TestModule, test_module,
| ^~~~~~~~~~~
tests/gobject/defaultiface.c: In function ‘test_static_iface_get_type’:
tests/gobject/defaultiface.c:58:1: error: missing initializer for field ‘class_finalize’ of ‘GTypeInfo’ {aka ‘const struct _GTypeInfo’}
58 | DEFINE_IFACE (TestStaticIface, test_static_iface,
| ^~~~~~~~~~~~
tests/gobject/testgobject.c: In function ‘test_iface_get_type’:
tests/gobject/testgobject.c:53:7: error: missing initializer for field ‘class_init’ of ‘GTypeInfo’ {aka ‘const struct _GTypeInfo’}
53 | };
| ^
tests/gobject/testgobject.c: In function ‘test_object_get_type’:
tests/gobject/testgobject.c:182:7: error: missing initializer for field ‘value_table’ of ‘GTypeInfo’ {aka ‘const struct _GTypeInfo’}
182 | };
| ^
tests/gobject/testgobject.c: In function ‘derived_object_get_type’:
tests/gobject/testgobject.c:349:7: error: missing initializer for field ‘value_table’ of ‘GTypeInfo’ {aka ‘const struct _GTypeInfo’}
349 | };
| ^
And drop the `volatile` qualifier from the variables, as that doesn’t
help with thread safety.
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: #600
These variables were already (correctly) accessed atomically. The
`volatile` qualifier doesn’t help with that.
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Helps: #600
This commit is the unmodified results of running
```
black $(git ls-files '*.py')
```
with black version 19.10b0. See #2046.
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>