static max lengths for the snprintfs etc

This commit is contained in:
DarthArgus
2016-08-01 03:02:50 +00:00
parent 3d7acd9f32
commit f4c737ddf7
3 changed files with 12 additions and 15 deletions
@@ -62,7 +62,7 @@ void FileLogObserver::prepareFile()
else
{
char buf[512];
IGNORE_RETURN( snprintf(buf, sizeof(buf), "%s-%d", m_filename.c_str(), m_fileIndex+1) );
IGNORE_RETURN( snprintf(buf, 512, "%s-%d", m_filename.c_str(), m_fileIndex+1) );
m_file = new StdioFile(buf, "a");
}
NOT_NULL(m_file);
@@ -91,7 +91,7 @@ void FileLogObserver::log(LogMessage const &msg)
std::string uniAttach(Unicode::wideToNarrow(msg.getUnicodeAttach()));
char tsbuf[16]; // yyyymmddhhmmss (14)
IGNORE_RETURN( snprintf(tsbuf, sizeof(tsbuf), UINT64_FORMAT_SPECIFIER, timestamp) );
IGNORE_RETURN( snprintf(tsbuf, 16, UINT64_FORMAT_SPECIFIER, timestamp) );
IGNORE_RETURN( m_file->write(14, tsbuf) );
IGNORE_RETURN( m_file->write(1, ":") );
IGNORE_RETURN( m_file->write(static_cast<int>(procId.length()), procId.c_str()) );
@@ -157,19 +157,19 @@ void LogManager::log(char const *format, ...)
if (!s_data)
return;
// if noone is observing log messages, no need to process them
if (s_data->logging == 1 && s_data->observers.size())
if (s_data->observers.size() && s_data->logging == 1)
{
++s_data->logging;
static char text[MaxLogMessageLen];
{
va_list ap;
va_start(ap, format); //lint !e746 !e1055
size_t len = strlen(text);
IGNORE_RETURN( _vsnprintf(text, MaxLogMessageLen, format, ap) );
text[MaxLogMessageLen-1] = '\0';
text[sizeof(text)-1] = '\0';
size_t len = strlen(text);
// if string was truncated, stick a + on the end
if (len == (MaxLogMessageLen-1))
text[len-1] = '+';
if (len == sizeof(text)-1)
text[len-1] = '+';
va_end(ap);
}
@@ -193,8 +193,9 @@ void LogManager::log(char const *format, ...)
timestamp *= 100;
timestamp += static_cast<unsigned int>(t.tm_sec);
}
observeLogMessage(LogMessage(timestamp, s_data->processIdentifier, s_data->channel, text, s_data->unicodeAttach));
--s_data->logging;
}
--s_data->logging;
@@ -206,12 +207,8 @@ void LogManager::log(char const *format, ...)
void LogManager::observeLogMessage(LogMessage const &msg)
{
for (ObserverList::iterator i = s_data->observers.begin(); i != s_data->observers.end(); ++i)
{
if (!(*i)->isFiltered(msg))
{
(*i)->log(msg);
}
}
}
// ----------------------------------------------------------------------
@@ -244,7 +241,7 @@ void LogManager::registerObserverType(std::string const &name, LogObserverCreate
s_data->observerCreateMap[name] = func;
char buffer[256];
sprintf(buffer, "%s:", name.c_str());
snprintf(buffer, 256, "%s:", name.c_str());
// run through SharedLog keys looking for logTarget=name:
{
@@ -93,7 +93,7 @@ void TailFileLogObserver::prepareFile()
else
{
char buf[512];
IGNORE_RETURN( snprintf(buf, sizeof(buf), "%s-%d", m_filename.c_str(), m_fileIndex+1) );
IGNORE_RETURN( snprintf(buf, 512, "%s-%d", m_filename.c_str(), m_fileIndex+1) );
m_file = new StdioFile(buf, "a");
}
NOT_NULL(m_file);
@@ -123,7 +123,7 @@ void TailFileLogObserver::log(LogMessage const &msg)
char tsbuf[16]; // yyyymmddhhmmss (14)
newLogMessage.clear();
IGNORE_RETURN( snprintf(tsbuf, sizeof(tsbuf), UINT64_FORMAT_SPECIFIER, timestamp) );
IGNORE_RETURN( snprintf(tsbuf, 16, UINT64_FORMAT_SPECIFIER, timestamp) );
newLogMessage.append(tsbuf);
newLogMessage.append(":");
newLogMessage.append(procId);