aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken/helper.cpp
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-12-13 14:31:05 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:18:34 -0300
commit4389601e22f8a8a3b5b6d4a92969030104cf4cd6 (patch)
tree000c309f0391ea0f9655e17d15a618ddb6ce4c50 /libshiboken/helper.cpp
parent016a34e8eb8d5be5ddd27d49ab141c59359beea7 (diff)
Fixed/refactored Shiboken::warning function.
Diffstat (limited to 'libshiboken/helper.cpp')
-rw-r--r--libshiboken/helper.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/libshiboken/helper.cpp b/libshiboken/helper.cpp
index 5213c514e..23483daad 100644
--- a/libshiboken/helper.cpp
+++ b/libshiboken/helper.cpp
@@ -96,7 +96,7 @@ int* sequenceToIntArray(PyObject* obj, bool zeroTerminated)
}
-int warning(PyObject *category, int stacklevel, const char *format, ...)
+int warning(PyObject* category, int stacklevel, const char* format, ...)
{
va_list args;
va_start(args, format);
@@ -107,16 +107,15 @@ int warning(PyObject *category, int stacklevel, const char *format, ...)
va_copy(args2, args);
#endif
- // check the necessary memmory
- int result = vsnprintf(NULL, 0, format, args);
- char *message = (char*) malloc(result);
+ // check the necessary memory
+ int size = vsnprintf(NULL, 0, format, args) + 1;
+ char* message = new char[size];
+ int result = 0;
if (message) {
// format the message
- vsnprintf(message, result, format, args2);
+ vsnprintf(message, size, format, args2);
result = PyErr_WarnEx(category, message, stacklevel);
- free(message);
- } else {
- result = 0;
+ delete message;
}
va_end(args2);
va_end(args);