mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-05 10:38:08 +01:00
tests: Add checks for buffer sizing in g_strlcat() tests
Just to ensure we’re passing a valid value for dest_size. Signed-off-by: Philip Withnall <withnall@endlessm.com> Helps: #1768
This commit is contained in:
parent
7541085589
commit
777a6030a6
@ -340,26 +340,31 @@ test_strlcat (void)
|
|||||||
* Note that the @dest_size argument to g_strlcat() is normally meant to be
|
* Note that the @dest_size argument to g_strlcat() is normally meant to be
|
||||||
* set to `sizeof (dest)`. We set it to various values `≤ sizeof (str_cpy)`
|
* set to `sizeof (dest)`. We set it to various values `≤ sizeof (str_cpy)`
|
||||||
* for testing purposes. */
|
* for testing purposes. */
|
||||||
|
g_assert_cmpuint (strlen (str) + 1, <=, sizeof (str_cpy));
|
||||||
str_cpy_size = g_strlcat (str_cpy, str, strlen (str) + 1);
|
str_cpy_size = g_strlcat (str_cpy, str, strlen (str) + 1);
|
||||||
g_assert_nonnull (str_cpy);
|
g_assert_nonnull (str_cpy);
|
||||||
g_assert_cmpstr (str, ==, str_cpy);
|
g_assert_cmpstr (str, ==, str_cpy);
|
||||||
g_assert_cmpint (str_cpy_size, ==, strlen (str));
|
g_assert_cmpint (str_cpy_size, ==, strlen (str));
|
||||||
|
|
||||||
|
g_assert_cmpuint (strlen (str), <=, sizeof (str_cpy));
|
||||||
str_cpy_size = g_strlcat (str_cpy, str, strlen (str));
|
str_cpy_size = g_strlcat (str_cpy, str, strlen (str));
|
||||||
g_assert_nonnull (str_cpy);
|
g_assert_nonnull (str_cpy);
|
||||||
g_assert_cmpstr (str, ==, str_cpy);
|
g_assert_cmpstr (str, ==, str_cpy);
|
||||||
g_assert_cmpint (str_cpy_size, ==, 2 * strlen (str));
|
g_assert_cmpint (str_cpy_size, ==, 2 * strlen (str));
|
||||||
|
|
||||||
|
g_assert_cmpuint (strlen (str) - 15, <=, sizeof (str_cpy));
|
||||||
str_cpy_size = g_strlcat (str_cpy, str, strlen (str) - 15);
|
str_cpy_size = g_strlcat (str_cpy, str, strlen (str) - 15);
|
||||||
g_assert_nonnull (str_cpy);
|
g_assert_nonnull (str_cpy);
|
||||||
g_assert_cmpstr (str, ==, str_cpy);
|
g_assert_cmpstr (str, ==, str_cpy);
|
||||||
g_assert_cmpint (str_cpy_size, ==, 2 * strlen (str) - 15);
|
g_assert_cmpint (str_cpy_size, ==, 2 * strlen (str) - 15);
|
||||||
|
|
||||||
|
g_assert_cmpuint (0, <=, sizeof (str_cpy));
|
||||||
str_cpy_size = g_strlcat (str_cpy, str, 0);
|
str_cpy_size = g_strlcat (str_cpy, str, 0);
|
||||||
g_assert_nonnull (str_cpy);
|
g_assert_nonnull (str_cpy);
|
||||||
g_assert_cmpstr (str, ==, str_cpy);
|
g_assert_cmpstr (str, ==, str_cpy);
|
||||||
g_assert_cmpint (str_cpy_size, ==, strlen (str));
|
g_assert_cmpint (str_cpy_size, ==, strlen (str));
|
||||||
|
|
||||||
|
g_assert_cmpuint (strlen (str) + 15, <=, sizeof (str_cpy));
|
||||||
str_cpy_size = g_strlcat (str_cpy, str, strlen (str) + 15);
|
str_cpy_size = g_strlcat (str_cpy, str, strlen (str) + 15);
|
||||||
g_assert_nonnull (str_cpy);
|
g_assert_nonnull (str_cpy);
|
||||||
g_assert_cmpstr ("The quick brown fox jumps over the lazy dogThe quick brow",
|
g_assert_cmpstr ("The quick brown fox jumps over the lazy dogThe quick brow",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user