Skip to content

fix: WriteNoFormat add null check #1307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions mars/comm/xlogger/xlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,19 @@ class XMessage {
#endif
XMessage&
WriteNoFormat(const char* _log) {
m_message += _log;
if (_log) {
m_message += _log;
}
return *this;
}
#ifdef __GNUC__
__attribute__((__format__(printf, 3, 0)))
#endif
XMessage&
WriteNoFormat(const TypeSafeFormat&, const char* _log) {
m_message += _log;
if (_log) {
m_message += _log;
}
return *this;
}

Expand Down Expand Up @@ -197,15 +201,19 @@ class XLogger {
#endif
XLogger&
WriteNoFormat(const char* _log) {
m_message += _log;
if (_log) {
m_message += _log;
}
return *this;
}
#ifdef __GNUC__
__attribute__((__format__(printf, 3, 0)))
#endif
XLogger&
WriteNoFormat(const TypeSafeFormat&, const char* _log) {
m_message += _log;
if (_log) {
m_message += _log;
}
return *this;
}

Expand Down
16 changes: 12 additions & 4 deletions mars/xlog/export_include/xlogger/xlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,19 @@ class XMessage {
#endif
XMessage&
WriteNoFormat(const char* _log) {
m_message += _log;
if (_log) {
m_message += _log;
}
return *this;
}
#ifdef __GNUC__
__attribute__((__format__(printf, 3, 0)))
#endif
XMessage&
WriteNoFormat(const TypeSafeFormat&, const char* _log) {
m_message += _log;
if (_log) {
m_message += _log;
}
return *this;
}

Expand Down Expand Up @@ -204,15 +208,19 @@ class XLogger {
#endif
XLogger&
WriteNoFormat(const char* _log) {
m_message += _log;
if (_log) {
m_message += _log;
}
return *this;
}
#ifdef __GNUC__
__attribute__((__format__(printf, 3, 0)))
#endif
XLogger&
WriteNoFormat(const TypeSafeFormat&, const char* _log) {
m_message += _log;
if (_log) {
m_message += _log;
}
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion mars/xlog/src/appender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void XloggerAppender::Write(const XLoggerInfo* _info, const char* _log) {
PtrBuffer tmp((void*)recursion_str.data(), 0, kMaxDumpLength);
log_formater(&info, recursive_log, tmp);

if (recursion_str.capacity() >= strnlen(_log, kMaxDumpLength)) {
if (_log && recursion_str.capacity() >= strnlen(_log, kMaxDumpLength)) {
recursion_str += _log;
}

Expand Down