summaryrefslogtreecommitdiff
path: root/src/core
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/core
parentc356b16322fc6d70d8e002796984e57dc5a20d8e (diff)
downloadweechat-ebf72c7eda87e70aed16e890581307f527567bed.zip
core: use dynamic buffer size for calls to vsnprintf
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-backtrace.c17
-rw-r--r--src/core/wee-completion.c2
-rw-r--r--src/core/wee-config-file.c20
-rw-r--r--src/core/wee-log.c65
-rw-r--r--src/core/wee-string.c31
5 files changed, 66 insertions, 69 deletions
diff --git a/src/core/wee-backtrace.c b/src/core/wee-backtrace.c
index 91c4f4727..fd121f084 100644
--- a/src/core/wee-backtrace.c
+++ b/src/core/wee-backtrace.c
@@ -44,6 +44,7 @@
#include "wee-backtrace.h"
#include "wee-log.h"
#include "wee-string.h"
+#include "../plugins/plugin.h"
/*
@@ -54,15 +55,13 @@
void
weechat_backtrace_printf (const char *message, ...)
{
- static char buffer[4096];
- va_list argptr;
-
- va_start (argptr, message);
- vsnprintf (buffer, sizeof (buffer) - 1, message, argptr);
- va_end (argptr);
-
- string_iconv_fprintf (stderr, "%s\n", buffer);
- log_printf ("%s", buffer);
+ weechat_va_format (message);
+ if (vbuffer)
+ {
+ string_iconv_fprintf (stderr, "%s\n", vbuffer);
+ log_printf ("%s", vbuffer);
+ free (vbuffer);
+ }
}
/*
diff --git a/src/core/wee-completion.c b/src/core/wee-completion.c
index 8cc3c974e..6f4bc06e2 100644
--- a/src/core/wee-completion.c
+++ b/src/core/wee-completion.c
@@ -42,7 +42,6 @@
#include "wee-list.h"
#include "wee-proxy.h"
#include "wee-string.h"
-#include "../plugins/plugin.h"
#include "../gui/gui-completion.h"
#include "../gui/gui-bar.h"
#include "../gui/gui-bar-window.h"
@@ -52,6 +51,7 @@
#include "../gui/gui-key.h"
#include "../gui/gui-nicklist.h"
#include "../gui/gui-window.h"
+#include "../plugins/plugin.h"
/*
diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c
index 966169e9d..12f3ac612 100644
--- a/src/core/wee-config-file.c
+++ b/src/core/wee-config-file.c
@@ -1872,22 +1872,24 @@ int
config_file_write_line (struct t_config_file *config_file,
const char *option_name, const char *value, ...)
{
- char buf[4096];
- va_list argptr;
+ int rc;
if (!config_file || !option_name)
return 0;
if (value && value[0])
{
- va_start (argptr, value);
- vsnprintf (buf, sizeof (buf) - 1, value, argptr);
- va_end (argptr);
-
- if (buf[0])
+ weechat_va_format (value);
+ if (vbuffer)
{
- return (string_iconv_fprintf (config_file->file, "%s = %s\n",
- option_name, buf));
+ if (vbuffer[0])
+ {
+ rc = string_iconv_fprintf (config_file->file, "%s = %s\n",
+ option_name, vbuffer);
+ free (vbuffer);
+ return rc;
+ }
+ free (vbuffer);
}
}
diff --git a/src/core/wee-log.c b/src/core/wee-log.c
index 716a05a53..97f5347bc 100644
--- a/src/core/wee-log.c
+++ b/src/core/wee-log.c
@@ -43,6 +43,7 @@
#include "wee-log.h"
#include "wee-debug.h"
#include "wee-string.h"
+#include "../plugins/plugin.h"
char *weechat_log_filename = NULL; /* log name (~/.weechat/weechat.log) */
@@ -125,48 +126,48 @@ log_init ()
void
log_printf (const char *message, ...)
{
- static char buffer[4096];
char *ptr_buffer;
- va_list argptr;
static time_t seconds;
struct tm *date_tmp;
if (!weechat_log_file)
return;
- va_start (argptr, message);
- vsnprintf (buffer, sizeof (buffer) - 1, message, argptr);
- va_end (argptr);
-
- /* keep only valid chars */
- ptr_buffer = buffer;
- while (ptr_buffer[0])
- {
- if ((ptr_buffer[0] != '\n')
- && (ptr_buffer[0] != '\r')
- && ((unsigned char)(ptr_buffer[0]) < 32))
- ptr_buffer[0] = '.';
- ptr_buffer++;
- }
-
- if (!weechat_log_use_time)
- string_iconv_fprintf (weechat_log_file, "%s\n", buffer);
- else
+ weechat_va_format (message);
+ if (vbuffer)
{
- seconds = time (NULL);
- date_tmp = localtime (&seconds);
- if (date_tmp)
- string_iconv_fprintf (weechat_log_file,
- "[%04d-%02d-%02d %02d:%02d:%02d] %s\n",
- date_tmp->tm_year + 1900, date_tmp->tm_mon + 1,
- date_tmp->tm_mday, date_tmp->tm_hour,
- date_tmp->tm_min, date_tmp->tm_sec,
- buffer);
+ /* keep only valid chars */
+ ptr_buffer = vbuffer;
+ while (ptr_buffer[0])
+ {
+ if ((ptr_buffer[0] != '\n')
+ && (ptr_buffer[0] != '\r')
+ && ((unsigned char)(ptr_buffer[0]) < 32))
+ ptr_buffer[0] = '.';
+ ptr_buffer++;
+ }
+
+ if (!weechat_log_use_time)
+ string_iconv_fprintf (weechat_log_file, "%s\n", vbuffer);
else
- string_iconv_fprintf (weechat_log_file, "%s\n", buffer);
+ {
+ seconds = time (NULL);
+ date_tmp = localtime (&seconds);
+ if (date_tmp)
+ string_iconv_fprintf (weechat_log_file,
+ "[%04d-%02d-%02d %02d:%02d:%02d] %s\n",
+ date_tmp->tm_year + 1900, date_tmp->tm_mon + 1,
+ date_tmp->tm_mday, date_tmp->tm_hour,
+ date_tmp->tm_min, date_tmp->tm_sec,
+ vbuffer);
+ else
+ string_iconv_fprintf (weechat_log_file, "%s\n", vbuffer);
+ }
+
+ fflush (weechat_log_file);
+
+ free (vbuffer);
}
-
- fflush (weechat_log_file);
}
/*
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index 06695b290..7ebee8c44 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -57,6 +57,7 @@
#include "wee-hashtable.h"
#include "wee-utf8.h"
#include "../gui/gui-color.h"
+#include "../plugins/plugin.h"
/*
@@ -1325,26 +1326,20 @@ string_iconv_from_internal (const char *charset, const char *string)
int
string_iconv_fprintf (FILE *file, const char *data, ...)
{
- va_list argptr;
- char *buf, *buf2;
+ char *buf2;
int rc, num_written;
- buf = malloc (128 * 1024);
- if (!buf)
- return 0;
-
- va_start (argptr, data);
- vsnprintf (buf, 128 * 1024, data, argptr);
- va_end (argptr);
-
- buf2 = string_iconv_from_internal (NULL, buf);
- num_written = fprintf (file, "%s", (buf2) ? buf2 : buf);
-
- rc = (num_written == (int)strlen ((buf2) ? buf2 : buf)) ? 1 : 0;
-
- free (buf);
- if (buf2)
- free (buf2);
+ rc = 0;
+ weechat_va_format (data);
+ if (vbuffer)
+ {
+ buf2 = string_iconv_from_internal (NULL, vbuffer);
+ num_written = fprintf (file, "%s", (buf2) ? buf2 : vbuffer);
+ rc = (num_written == (int)strlen ((buf2) ? buf2 : vbuffer)) ? 1 : 0;
+ if (buf2)
+ free (buf2);
+ free (vbuffer);
+ }
return rc;
}