提交 550db707 authored 作者: Michael Jerris's avatar Michael Jerris

a little realloc never hurt anyone.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4756 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 67acaefc
...@@ -657,8 +657,31 @@ SWITCH_DECLARE(int) switch_vasprintf(char **buf, const char *format, va_list ap) ...@@ -657,8 +657,31 @@ SWITCH_DECLARE(int) switch_vasprintf(char **buf, const char *format, va_list ap)
#ifdef HAVE_VASPRINTF #ifdef HAVE_VASPRINTF
return vasprintf(buf, format, ap); return vasprintf(buf, format, ap);
#else #else
*buf = (char *) malloc(2048); size_t block_size = 1024;
return vsnprintf(*buf, 2048, format, ap); int ret = -1;
int count = 1;
*buf = (char *) malloc(block_size);
if (*buf == NULL) {
return -1;
}
while (ret == -1 && count < 10) {
ret = vsnprintf(*buf, block_size*count, format, ap);
if (ret == -1) {
void *new_buf;
count++;
new_buf = realloc(*buf, block_size*count);
if (new_buf == NULL) {
*buf = NULL;
return -1;
} else {
*buf = new_buf;
}
}
}
return ret;
#endif #endif
} }
......
...@@ -41,7 +41,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_stream_write(switch_stream_handle ...@@ -41,7 +41,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_stream_write(switch_stream_handle
char *buf = handle->data; char *buf = handle->data;
char *end = handle->end; char *end = handle->end;
int ret = 0; int ret = 0;
char *data; char *data = NULL;
if (handle->data_len >= handle->data_size) { if (handle->data_len >= handle->data_size) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论