[pygobject/pygobject-3-4] Fix pyg_value_from_pyobject() range check for uint
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/pygobject-3-4] Fix pyg_value_from_pyobject() range check for uint
- Date: Fri, 30 Nov 2012 07:58:03 +0000 (UTC)
commit ba44a6a49c42fcb3b6285f06f0bfee1c231c7a99
Author: Martin Pitt <martinpitt gnome org>
Date: Thu Nov 29 14:11:29 2012 +0100
Fix pyg_value_from_pyobject() range check for uint
We cannot use PYGLIB_PyLong_AsLong() for the range check, as on 32 bit machines
this overflows large uints. Use PyLong_AsLongLong() separately to check for
negative values, and PyLong_AsUnsignedLong() for the actual conversion.
gi/_gobject/pygtype.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/gi/_gobject/pygtype.c b/gi/_gobject/pygtype.c
index fe2c3b6..c803db3 100644
--- a/gi/_gobject/pygtype.c
+++ b/gi/_gobject/pygtype.c
@@ -831,11 +831,15 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
case G_TYPE_UINT:
{
if (PYGLIB_PyLong_Check(obj)) {
- glong val;
+ guint val;
- val = PYGLIB_PyLong_AsLong(obj);
- if (val >= 0 && val <= G_MAXUINT)
- g_value_set_uint(value, (guint)val);
+ /* check that number is not negative */
+ if (PyLong_AsLongLong(obj) < 0)
+ return -1;
+
+ val = PyLong_AsUnsignedLong(obj);
+ if (val <= G_MAXUINT)
+ g_value_set_uint(value, val);
else
return -1;
} else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]