[pygobject] Fix pyg_value_from_pyobject() range check for uint



commit 3fa31b1a7936c556e76bd8a42030567c6a867e0d
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 adc8c12..79c8387 100644
--- a/gi/_gobject/pygtype.c
+++ b/gi/_gobject/pygtype.c
@@ -811,11 +811,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]