BPython:
authorWillian Padovani Germano <wpgermano@gmail.com>
Tue, 27 Jun 2006 17:51:11 +0000 (17:51 +0000)
committerWillian Padovani Germano <wpgermano@gmail.com>
Tue, 27 Jun 2006 17:51:11 +0000 (17:51 +0000)
Bug #4484:

http://projects.blender.org/tracker/?func=detail&aid=4484&group_id=9&atid=125

A recent update to Draw.c made the button attr setter function not exit
where it should for one of the cases, when new and old strings had
same length (code was missing a "return 0;" line in one of the if
cases). Should work fine now, I don't get the error under linux anymore.
Also saw in the same function that a py object could be created but
was not being decref'ed in two other 'if' cases.

Thanks elbarto for reporting the bug.

source/blender/python/api2_2x/Draw.c

index ad26235a4771894ae79b51372764f7804fc12180..d2a1331d4eb286a55d32d2c651aa684e5363d34f 100644 (file)
@@ -406,6 +406,7 @@ static int Button_setattr( PyObject * self, char *name, PyObject * v )
                        PyObject *pyVal = PyNumber_Int( v );
                        if (pyVal) {
                                but->val.asint = (int)PyInt_AS_LONG( pyVal );
+                               Py_DECREF(pyVal);
                                return 0;
                        }
                }
@@ -413,6 +414,7 @@ static int Button_setattr( PyObject * self, char *name, PyObject * v )
                        PyObject *pyVal = PyNumber_Float( v );
                        if (pyVal) {
                                but->val.asfloat = (float)PyFloat_AS_DOUBLE( pyVal );
+                               Py_DECREF(pyVal);
                                return 0;
                        }
                }
@@ -427,13 +429,16 @@ static int Button_setattr( PyObject * self, char *name, PyObject * v )
                        PyString_AsStringAndSize( v, &newstr, &newlen );
                        
                        if (newlen+1> UI_MAX_DRAW_STR)
-                               return EXPP_ReturnIntError( PyExc_ValueError, "Error, the string assigned to this button has a length greator then 399");
-                       
+                               return EXPP_ReturnIntError( PyExc_ValueError, "Error: button string length exceeded max limit (399 chars).");
+
                        /* if the length of the new string is the same as */
                        /* the old one, just copy, else delete and realloc. */
                        if( but->slen == newlen ) {
                                BLI_strncpy( but->val.asstr, newstr,
                                             but->slen + 1 );
+
+                               return 0;
+
                        } else {
                                MEM_freeN( but->val.asstr );
                                but->slen = newlen;