1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-07 18:23:13 +02:00

core: use dynamic buffer size for calls to vsnprintf

This commit is contained in:
Sebastien Helleu
2011-08-26 09:55:55 +02:00
parent c356b16322
commit ebf72c7eda
13 changed files with 190 additions and 191 deletions
+8 -9
View File
@@ -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);
}
}
/*
+1 -1
View File
@@ -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"
/*
+11 -9
View File
@@ -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);
}
}
+33 -32
View File
@@ -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])
weechat_va_format (message);
if (vbuffer)
{
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
{
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);
}
/*
+13 -18
View File
@@ -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;
}