[glib/wip/3v1n0/g_str_has_optimization] gstrfuncs: workaround build failure with some compilers
- From: Marco Trevisan <marcotrevi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/3v1n0/g_str_has_optimization] gstrfuncs: workaround build failure with some compilers
- Date: Thu, 13 Oct 2022 00:42:56 +0000 (UTC)
commit 61f36ec97bbec0e79b437f067c45236427efca42
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Thu Oct 13 02:18:00 2022 +0200
gstrfuncs: workaround build failure with some compilers
For some reason we may get warnings about using NULL parameters, while
this is impossible
glib/gstrfuncs.h | 8 ++++----
glib/tests/strfuncs.c | 8 ++++++++
2 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/glib/gstrfuncs.h b/glib/gstrfuncs.h
index 19eb291bef..f8c09f335a 100644
--- a/glib/gstrfuncs.h
+++ b/glib/gstrfuncs.h
@@ -151,8 +151,8 @@ gboolean g_str_has_prefix (const gchar *str,
(((STR) != NULL && (PREFIX) != NULL && __builtin_constant_p ((PREFIX))) ? \
G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof (PREFIX[0]) == sizeof (char)); \
- const char *const __str = ((STR)); \
- const char *const __prefix = ((PREFIX)); \
+ const char *const __str = ((STR) + !(STR)); \
+ const char *const __prefix = ((PREFIX) + !(PREFIX)); \
const size_t __str_len = strlen (__str); \
const size_t __prefix_len = sizeof ((PREFIX)) - 1; \
(__str_len >= __prefix_len) ? \
@@ -165,8 +165,8 @@ gboolean g_str_has_prefix (const gchar *str,
(((STR) != NULL && (SUFFIX) != NULL && __builtin_constant_p ((SUFFIX))) ? \
G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof (SUFFIX[0]) == sizeof (char)); \
- const char *const __str = ((STR)); \
- const char *const __suffix = ((SUFFIX)); \
+ const char *const __str = ((STR) + !(STR)); \
+ const char *const __suffix = ((SUFFIX) + !(SUFFIX)); \
const size_t __str_len = strlen (__str); \
const size_t __suffix_len = sizeof ((SUFFIX)) - 1; \
(__str_len >= __suffix_len) ? \
diff --git a/glib/tests/strfuncs.c b/glib/tests/strfuncs.c
index e7d3e108e7..fdc2b3a54a 100644
--- a/glib/tests/strfuncs.c
+++ b/glib/tests/strfuncs.c
@@ -1285,7 +1285,15 @@ test_has_prefix_macro (void)
rand_str[7] = 'A';
rand_str[8] = 'A';
rand_str[9] = '\0';
+
+#if G_GNUC_CHECK_VERSION (2, 0)
+ _Pragma ("GCC diagnostic push")
+ _Pragma ("GCC diagnostic ignored \"-Waddress\"")
+ g_assert_true (g_str_has_prefix (rand_str, rand_prefix));
+ _Pragma ("GCC diagnostic pop")
+#else
g_assert_true (g_str_has_prefix (rand_str, rand_prefix));
+#endif
res = g_str_has_prefix ("foo", "bar");
g_assert_cmpint (res, ==, FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]