From 6f10660f0c47a76bf8e620701a39e7697eac7654 Mon Sep 17 00:00:00 2001 From: Alexander Ewering Date: Fri, 23 Dec 2005 22:16:33 +0000 Subject: Fixing a bit of horrible code in Armature.c (BonesDict_repr). There is a lot of very dangerous (and slow) string manipulation code in there. I do not want to appear arrogant, but a bit of basic code QA in this module certainly can't hurt. Please see the diff for further explanation ;-) --- source/blender/python/api2_2x/Armature.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'source/blender/python/api2_2x/Armature.c') diff --git a/source/blender/python/api2_2x/Armature.c b/source/blender/python/api2_2x/Armature.c index d732ad38d71..2154b28988a 100644 --- a/source/blender/python/api2_2x/Armature.c +++ b/source/blender/python/api2_2x/Armature.c @@ -172,28 +172,25 @@ static int BonesDict_InitEditBones(BPy_BonesDict *self) //This is the string representation of the object static PyObject *BonesDict_repr(BPy_BonesDict *self) { - char buffer[128], str[4096]; + char str[4096]; PyObject *key, *value; int pos = 0; + char *p = str; + + p += sprintf(str, "[Bone Dict: {"); - BLI_strncpy(str,"",4096); - sprintf(buffer, "[Bone Dict: {"); - strcat(str,buffer); if (self->editmode_flag){ while (PyDict_Next(self->editbonesMap, &pos, &key, &value)) { - sprintf(buffer, "%s : %s, ", PyString_AsString(key), + p += sprintf(p, "%s : %s, ", PyString_AsString(key), PyString_AsString(value->ob_type->tp_repr(value))); - strcat(str,buffer); } }else{ while (PyDict_Next(self->bonesMap, &pos, &key, &value)) { - sprintf(buffer, "%s : %s, ", PyString_AsString(key), + p += sprintf(p, "%s : %s, ", PyString_AsString(key), PyString_AsString(value->ob_type->tp_repr(value))); - strcat(str,buffer); } } - sprintf(buffer, "}]\n"); - strcat(str,buffer); + p += sprintf(p, "}]\n"); return PyString_FromString(str); } -- cgit v1.2.3