[gjs/gnome-3-24] arg: Avoid assigning out-of-range values
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/gnome-3-24] arg: Avoid assigning out-of-range values
- Date: Fri, 8 Sep 2017 03:42:12 +0000 (UTC)
commit 565161f038ad32e4c8f985f20d9dfd86cbca1435
Author: Philip Chimento <philip chimento gmail com>
Date: Tue Aug 29 23:19:02 2017 -0700
arg: Avoid assigning out-of-range values
Assigning out-of-range values to variables of these types is undefined
behaviour, and was caught by UBSan on Clang.
https://bugzilla.gnome.org/show_bug.cgi?id=786995
gi/arg.cpp | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index c961ebe..4b42550 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -1390,7 +1390,7 @@ gjs_value_to_g_argument(JSContext *context,
wrong = true;
if (i > G_MAXUINT32 || i < 0)
out_of_range = true;
- arg->v_uint32 = (guint32)i;
+ arg->v_uint32 = CLAMP(i, 0, G_MAXUINT32);
break;
}
@@ -1411,7 +1411,7 @@ gjs_value_to_g_argument(JSContext *context,
if (v < 0)
out_of_range = true;
/* XXX we fail with values close to G_MAXUINT64 */
- arg->v_uint64 = v;
+ arg->v_uint64 = MAX(v, 0);
}
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]