未验证 提交 aaa8f646 编写于 作者: L Longda 提交者: GitHub

Closes #131, replace sprintf with snprintf (#134)

上级 83b1d4e3
......@@ -194,7 +194,7 @@ char *bin_to_hex(const char *s, const int len, char *hex_buff)
int new_len = 0;
unsigned char *end = (unsigned char *)s + len;
for (unsigned char *p = (unsigned char *)s; p < end; p++) {
new_len += sprintf(hex_buff + new_len, "%02x", *p);
new_len += snprintf(hex_buff + new_len, 2, "%02x", *p);
}
hex_buff[new_len] = '\0';
......
......@@ -157,14 +157,16 @@ extern Log *g_log;
#define __FILE_NAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#endif
#define LOG_HEAD_SIZE 64
#define LOG_HEAD(prefix, level) \
if (common::g_log) { \
time_t now_time; \
time(&now_time); \
struct tm *p = localtime(&now_time); \
char sz_head[64] = {0}; \
char sz_head[LOG_HEAD_SIZE] = {0}; \
if (p) { \
sprintf(sz_head, \
snprintf(sz_head, LOG_HEAD_SIZE, \
"%d-%d-%d %d:%d:%u pid:%u tid:%llx ", \
p->tm_year + 1900, \
p->tm_mon + 1, \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册