[glib] type-test: do not rely on signed integer overflow wrapping around
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] type-test: do not rely on signed integer overflow wrapping around
- Date: Fri, 2 Dec 2016 19:11:54 +0000 (UTC)
commit 0d28ee458f1847b3c7f3ed810b28b9a988ece40a
Author: Simon McVittie <smcv debian org>
Date: Fri Dec 2 10:22:00 2016 +0000
type-test: do not rely on signed integer overflow wrapping around
Signed integer overflow is undefined behaviour: if a compiler
detects signed integer overflow, it is free to compile it to absolutely
anything.
Signed-off-by: Simon McVittie <smcv debian org>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=775510
Reviewed-by: Colin Walters
tests/type-test.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
---
diff --git a/tests/type-test.c b/tests/type-test.c
index e767f0f..2e91565 100644
--- a/tests/type-test.c
+++ b/tests/type-test.c
@@ -88,15 +88,15 @@ main (int argc,
g_assert (gsz == 0);
gs = G_MAXSHORT;
- gs++;
+ gs = (gshort) (1 + (gushort) gs);
g_assert (gs == G_MINSHORT);
gi = G_MAXINT;
- gi++;
+ gi = (gint) (1 + (guint) gi);
g_assert (gi == G_MININT);
gl = G_MAXLONG;
- gl++;
+ gl = (glong) (1 + (gulong) gl);
g_assert (gl == G_MINLONG);
/* Test the G_G(U)?INT(16|32|64)_FORMAT macros */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]