[glib: 1/2] Fix always true comparison warning in glib/garray.c
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] Fix always true comparison warning in glib/garray.c
- Date: Thu, 4 Nov 2021 14:18:04 +0000 (UTC)
commit 12113f398ae4375bb5d1f102a50aa973da74082b
Author: Emmanuel Fleury <emmanuel fleury gmail com>
Date: Mon Oct 25 17:11:59 2021 +0200
Fix always true comparison warning in glib/garray.c
glib.git/glib/garray.c: In function ‘g_array_new’:
glib.git/glib/garray.c:184:34: error: comparison is always true due to limited range of data type
[-Werror=type-limits]
184 | g_return_val_if_fail (elt_size <= G_MAXSIZE / 2 - 1, NULL);
| ^~
glib.git/glib/gmacros.h:1090:25: note: in definition of macro ‘G_LIKELY’
1090 | #define G_LIKELY(expr) (expr)
| ^~~~
glib.git/glib/garray.c:184:3: note: in expansion of macro ‘g_return_val_if_fail’
184 | g_return_val_if_fail (elt_size <= G_MAXSIZE / 2 - 1, NULL);
| ^~~~~~~~~~~~~~~~~~~~
glib.git/glib/garray.c: In function ‘g_array_sized_new’:
glib.git/glib/garray.c:265:34: error: comparison is always true due to limited range of data type
[-Werror=type-limits]
265 | g_return_val_if_fail (elt_size <= G_MAXSIZE, NULL);
| ^~
glib.git/glib/gmacros.h:1090:25: note: in definition of macro ‘G_LIKELY’
1090 | #define G_LIKELY(expr) (expr)
| ^~~~
glib.git/glib/garray.c:265:3: note: in expansion of macro ‘g_return_val_if_fail’
265 | g_return_val_if_fail (elt_size <= G_MAXSIZE, NULL);
| ^~~~~~~~~~~~~~~~~~~~
glib/garray.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/glib/garray.c b/glib/garray.c
index d07244190..254921247 100644
--- a/glib/garray.c
+++ b/glib/garray.c
@@ -181,7 +181,9 @@ g_array_new (gboolean zero_terminated,
guint elt_size)
{
g_return_val_if_fail (elt_size > 0, NULL);
+#if (UINT_WIDTH / 8) >= GLIB_SIZEOF_SIZE_T
g_return_val_if_fail (elt_size <= G_MAXSIZE / 2 - 1, NULL);
+#endif
return g_array_sized_new (zero_terminated, clear, elt_size, 0);
}
@@ -262,7 +264,9 @@ g_array_sized_new (gboolean zero_terminated,
GRealArray *array;
g_return_val_if_fail (elt_size > 0, NULL);
- g_return_val_if_fail (elt_size <= G_MAXSIZE, NULL);
+#if (UINT_WIDTH / 8) >= GLIB_SIZEOF_SIZE_T
+ g_return_val_if_fail (elt_size <= G_MAXSIZE / 2 - 1, NULL);
+#endif
array = g_slice_new (GRealArray);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]