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 ;-)
This commit is contained in:
Alexander Ewering 2005-12-23 22:16:33 +00:00
parent e8f7ff2ffb
commit 6f10660f0c

@ -172,28 +172,25 @@ static int BonesDict_InitEditBones(BPy_BonesDict *self)
//This is the string representation of the object //This is the string representation of the object
static PyObject *BonesDict_repr(BPy_BonesDict *self) static PyObject *BonesDict_repr(BPy_BonesDict *self)
{ {
char buffer[128], str[4096]; char str[4096];
PyObject *key, *value; PyObject *key, *value;
int pos = 0; 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){ if (self->editmode_flag){
while (PyDict_Next(self->editbonesMap, &pos, &key, &value)) { 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))); PyString_AsString(value->ob_type->tp_repr(value)));
strcat(str,buffer);
} }
}else{ }else{
while (PyDict_Next(self->bonesMap, &pos, &key, &value)) { 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))); PyString_AsString(value->ob_type->tp_repr(value)));
strcat(str,buffer);
} }
} }
sprintf(buffer, "}]\n"); p += sprintf(p, "}]\n");
strcat(str,buffer);
return PyString_FromString(str); return PyString_FromString(str);
} }