fixed a security bug in logging, added basic xml support to as3 compiler
[swftools.git] / lib / python / pyutils.c
index 5f7b7d4..f5362fc 100644 (file)
@@ -10,7 +10,7 @@ char* setError(char*format, ...)
     int l;
     va_list arglist;
     va_start(arglist, format);
-    vsprintf(buf, format, arglist);
+    vsnprintf(buf, sizeof(buf)-1, format, arglist);
     va_end(arglist);
     l = strlen(buf);
     while(l && buf[l-1]=='\n') {
@@ -20,7 +20,7 @@ char* setError(char*format, ...)
     return strdup(buf);
 }
 
-int verbose = 1;
+static int verbose = 0;
 void mylog(char*format, ...)
 {
     char buf[1024];
@@ -29,7 +29,7 @@ void mylog(char*format, ...)
     if(!verbose)
        return;
     va_start(arglist, format);
-    vsprintf(buf, format, arglist);
+    vsnprintf(buf, sizeof(buf)-1, format, arglist);
     va_end(arglist);
     l = strlen(buf);
     while(l && buf[l-1]=='\n') {
@@ -64,3 +64,22 @@ void dummy_dealloc(PyObject* self)
     PyObject_Del(self);
 }
 
+PyMethodDef* addMethods(PyMethodDef*obj1, PyMethodDef*obj2) 
+{
+    int num1=0,num2=0;
+    if(obj1) for(num1=0;obj1[num1].ml_name;num1++);
+    if(obj2) for(num2=0;obj2[num2].ml_name;num2++);
+    PyMethodDef* result = malloc(sizeof(PyMethodDef)*(num1+num2+1));
+    if(obj1)
+       memcpy(result, obj1, num1*sizeof(PyMethodDef));
+    if(obj2)
+       memcpy(&result[num1], obj2, (num2+1)*sizeof(PyMethodDef));
+    if(obj1)
+       free(obj1);
+    return result;
+}
+void setVerbosity(int _verbose)
+{
+    verbose = _verbose;
+    mylog("setting verbosity to %d", verbose);
+}