When get_help() gets ready to lay out the help text into columns,
it first goes through and computes the max_width of the strings in
the left column. Problem is, it measures the width of every
available option, whether or not they'll actually be displayed.
Instead, let's use the same criteria used when deciding whether
to display an option, to decide whether or not to account for it
when computing max_width. This way, the layout is sized for the
help that's actually being produced.
Fixes#3781
Always NUL-terminate the data, which g_file_get_contents does as well.
This fixes unnecessary fuzzer warnings.
For further clarification of this requirement, rename the internally
used function.
Fixes: #3783
Do what the comment states and strip all trailing slashes. Also, do not
strip the trailing slash if it's the only character left, i.e. if it
denotes the root directory.
XDG_CONFIG_DIR and HOME can be overridden with test environments. Read
these variables before building them again.
It's not possible to call the getter functions directly because the
caller of load_user_special_dirs already holds a lock and locking again
is undefined behavior and could lead to deadlocks.
Separate the functionality out into unlocked functions which definitely
have to be static to not expose them. Use them while holding the lock.
Allow more than G_MAXUINT replacements in g_string_replace. Even
though the return value type is guint, do as many replacements
as requested if limit is 0 and return G_MAXUINT if even more
operations were performed to satisfy current ABI/API.
With input by Philip Withnall.
If the input string is too large on a 32 bit system, it is possible
to trigger an integer overflow which subsequently leads to an out of
boundary write.
The gintptr data type is already used in iterator. Keep versions in sync
to avoid issues when one of them overflows while the other did not
(yet). Since integer overflows could eventually happen anyway, make
version unsigned.
The size attribute is actually a "capacity" instead of a size in a more
classical sense: It doesn't represent the byte size but the amount of
elements within the hash table.
This is always a power of two, capped at 32 bit. This limit is required
to satisfy the support of converting a GHash into a GArray, which is
capped at G_MAXUINT elements.
Treat the size as capacity and bring it to the same data type as nnodes
and other element counters for better performance.
While at it, turn all variables taking the value of size into a guint
as well.
Closes: #672
Having unsigned values guarantees that g_hash_table_find_closest_shift
will never loop endlessly. Also make sure that it's impossible to
evade the sanity check of size in g_hash_table_set_shift. Since the
value will be an index, do not allow negative values.
Helps: #672
If nnodes value is very large, multiplying by 4 could overflow its guint
data type. Instead, first check that size is not 0, subtract by one, divide
by 4 and then check if that value is larger or equal to nnodes.
Flipping these checks has a nice advantage for small hash tables.
Helps: #672
Using the builtin multiplication checks leads to less instructions used
for these common functions (true for clang as well as gcc on x86_64).
Also, from a C perspective, the result is re-used, making code audits
easier.
With these adjustments, building with clang leads to no warnings:
- The "{ NULL }" statement could be replaced with "{ 0 }" to satisfy
clang, but this way it's explicitly filling all fields
- Even though "i" is not read with these g_array_binary_search calls,
it rightfully should be set