null terminating snprintf

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10907 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2008-12-22 16:27:39 +00:00
parent d72a4ea77d
commit 6881efcf6c
4 changed files with 23 additions and 3 deletions

View File

@ -175,6 +175,24 @@ const char *esl_stristr(const char *instr, const char *str)
return NULL;
}
#ifdef WIN32
#ifndef vsnprintf
#define vsnprintf _vsnprintf
#endif
#endif
int esl_snprintf(char *buffer, size_t count, const char *fmt, ...)
{
va_list ap;
int ret;
va_start(ap, fmt);
ret = vsnprintf(buffer, count-1, fmt, ap);
if (ret < 0)
buffer[count-1] = '\0';
va_end(ap);
return ret;
}
static void null_logger(const char *file, const char *func, int line, int level, const char *fmt, ...)
{

View File

@ -43,7 +43,7 @@ int esl_config_open_file(esl_config_t *cfg, const char *file_path)
if (file_path[0] == '/') {
path = file_path;
} else {
snprintf(path_buf, sizeof(path_buf), "%s%s%s", ESL_CONFIG_DIR, ESL_PATH_SEPARATOR, file_path);
esl_snprintf(path_buf, sizeof(path_buf), "%s%s%s", ESL_CONFIG_DIR, ESL_PATH_SEPARATOR, file_path);
path = path_buf;
}
@ -61,7 +61,7 @@ int esl_config_open_file(esl_config_t *cfg, const char *file_path)
int last = -1;
char *var, *val;
snprintf(path_buf, sizeof(path_buf), "%s%sopenesl.conf", ESL_CONFIG_DIR, ESL_PATH_SEPARATOR);
esl_snprintf(path_buf, sizeof(path_buf), "%s%sopenesl.conf", ESL_CONFIG_DIR, ESL_PATH_SEPARATOR);
path = path_buf;
if ((f = fopen(path, "r")) == 0) {

View File

@ -481,7 +481,7 @@ esl_status_t esl_event_serialize(esl_event_t *event, char **str, esl_bool_t enco
if (encode) {
esl_url_encode(hp->value, encode_buf, encode_len);
} else {
snprintf(encode_buf, encode_len, "[%s]", hp->value);
esl_snprintf(encode_buf, encode_len, "[%s]", hp->value);
}
llen = strlen(hp->name) + strlen(encode_buf) + 8;

View File

@ -284,6 +284,8 @@ char *esl_url_decode(char *s);
const char *esl_stristr(const char *instr, const char *str);
int esl_toupper(int c);
int esl_tolower(int c);
int esl_snprintf(char *buffer, size_t count, const char *fmt, ...);
typedef void (*esl_listen_callback_t)(esl_socket_t server_sock, esl_socket_t client_sock, struct sockaddr_in addr);