summaryrefslogtreecommitdiff
path: root/src/plugins/scripts/script-api.c
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2011-08-26 09:55:55 +0200
committerSebastien Helleu <flashcode@flashtux.org>2011-08-26 09:55:55 +0200
commitebf72c7eda87e70aed16e890581307f527567bed (patch)
treefa0b2af5ed236bd33afdbe53ebb4efcfc447a590 /src/plugins/scripts/script-api.c
parentc356b16322fc6d70d8e002796984e57dc5a20d8e (diff)
downloadweechat-ebf72c7eda87e70aed16e890581307f527567bed.zip
core: use dynamic buffer size for calls to vsnprintf
Diffstat (limited to 'src/plugins/scripts/script-api.c')
-rw-r--r--src/plugins/scripts/script-api.c80
1 files changed, 31 insertions, 49 deletions
diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c
index 9f05f6d2c..2c04d0b80 100644
--- a/src/plugins/scripts/script-api.c
+++ b/src/plugins/scripts/script-api.c
@@ -609,24 +609,19 @@ script_api_printf (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer, const char *format, ...)
{
- va_list argptr;
- char *buf, *buf2;
+ char *buf2;
- buf = malloc (128 * 1024);
- if (!buf)
+ weechat_va_format (format);
+ if (!vbuffer)
return;
- va_start (argptr, format);
- vsnprintf (buf, 128 * 1024, format, argptr);
- va_end (argptr);
-
buf2 = (script && script->charset && script->charset[0]) ?
- weechat_iconv_to_internal (script->charset, buf) : NULL;
- weechat_printf (buffer, "%s", (buf2) ? buf2 : buf);
-
- free (buf);
+ weechat_iconv_to_internal (script->charset, vbuffer) : NULL;
+ weechat_printf (buffer, "%s", (buf2) ? buf2 : vbuffer);
if (buf2)
free (buf2);
+
+ free (vbuffer);
}
/*
@@ -640,25 +635,20 @@ script_api_printf_date_tags (struct t_weechat_plugin *weechat_plugin,
time_t date, const char *tags,
const char *format, ...)
{
- va_list argptr;
- char *buf, *buf2;
-
- buf = malloc (128 * 1024);
- if (!buf)
- return;
+ char *buf2;
- va_start (argptr, format);
- vsnprintf (buf, 128 * 1024, format, argptr);
- va_end (argptr);
+ weechat_va_format (format);
+ if (!vbuffer)
+ return;
buf2 = (script->charset && script->charset[0]) ?
- weechat_iconv_to_internal (script->charset, buf) : NULL;
+ weechat_iconv_to_internal (script->charset, vbuffer) : NULL;
weechat_printf_date_tags (buffer, date, tags,
- "%s", (buf2) ? buf2 : buf);
-
- free (buf);
+ "%s", (buf2) ? buf2 : vbuffer);
if (buf2)
free (buf2);
+
+ free (vbuffer);
}
/*
@@ -671,24 +661,19 @@ script_api_printf_y (struct t_weechat_plugin *weechat_plugin,
struct t_gui_buffer *buffer, int y,
const char *format, ...)
{
- va_list argptr;
- char *buf, *buf2;
-
- buf = malloc (128 * 1024);
- if (!buf)
- return;
+ char *buf2;
- va_start (argptr, format);
- vsnprintf (buf, 128 * 1024, format, argptr);
- va_end (argptr);
+ weechat_va_format (format);
+ if (!vbuffer)
+ return;
buf2 = (script->charset && script->charset[0]) ?
- weechat_iconv_to_internal (script->charset, buf) : NULL;
- weechat_printf_y (buffer, y, "%s", (buf2) ? buf2 : buf);
-
- free (buf);
+ weechat_iconv_to_internal (script->charset, vbuffer) : NULL;
+ weechat_printf_y (buffer, y, "%s", (buf2) ? buf2 : vbuffer);
if (buf2)
free (buf2);
+
+ free (vbuffer);
}
/*
@@ -700,22 +685,19 @@ script_api_log_printf (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *format, ...)
{
- va_list argptr;
- char *buf, *buf2;
-
- buf = malloc (128 * 1024);
+ char *buf2;
- va_start (argptr, format);
- vsnprintf (buf, 128 * 1024, format, argptr);
- va_end (argptr);
+ weechat_va_format (format);
+ if (!vbuffer)
+ return;
buf2 = (script->charset && script->charset[0]) ?
- weechat_iconv_to_internal (script->charset, buf) : NULL;
- weechat_log_printf ("%s", (buf2) ? buf2 : buf);
-
- free (buf);
+ weechat_iconv_to_internal (script->charset, vbuffer) : NULL;
+ weechat_log_printf ("%s", (buf2) ? buf2 : vbuffer);
if (buf2)
free (buf2);
+
+ free (vbuffer);
}
/*