提交 2ea0452c 编写于 作者: J Joey Pabalinas 提交者: Greg Kroah-Hartman

tty/nozomi: cleanup DUMP() macro

Replace snprint() with strscpy() and use min_t() instead of
the conditional operator to clamp buffer length.
Signed-off-by: NJoey Pabalinas <joeypabalinas@gmail.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 c1c734cb
......@@ -72,19 +72,19 @@ do { \
#define TMP_BUF_MAX 256
#define DUMP(buf__,len__) \
do { \
char tbuf[TMP_BUF_MAX] = {0};\
if (len__ > 1) {\
snprintf(tbuf, len__ > TMP_BUF_MAX ? TMP_BUF_MAX : len__, "%s", buf__);\
if (tbuf[len__-2] == '\r') {\
tbuf[len__-2] = 'r';\
} \
DBG1("SENDING: '%s' (%d+n)", tbuf, len__);\
} else {\
DBG1("SENDING: '%s' (%d)", tbuf, len__);\
} \
} while (0)
#define DUMP(buf__, len__) \
do { \
char tbuf[TMP_BUF_MAX] = {0}; \
if (len__ > 1) { \
u32 data_len = min_t(u32, len__, TMP_BUF_MAX); \
strscpy(tbuf, buf__, data_len); \
if (tbuf[data_len - 2] == '\r') \
tbuf[data_len - 2] = 'r'; \
DBG1("SENDING: '%s' (%d+n)", tbuf, len__); \
} else { \
DBG1("SENDING: '%s' (%d)", tbuf, len__); \
} \
} while (0)
/* Defines */
#define NOZOMI_NAME "nozomi"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册