Skip to content
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

Add code to ensure no nullptr references. #512

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 10 additions & 2 deletions src/easylogging++.cc
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,10 @@ void Logger::flush(Level level, base::type::fstream_t* fs) {
}
if (fs != nullptr) {
fs->flush();
m_unflushedCount.find(level)->second = 0;
std::map<Level, unsigned int>::iterator i = m_unflushedCount.find(level);
if (i != m_unflushedCount.end()) {
i->second = 0;
}
}
}

Expand Down Expand Up @@ -996,6 +999,9 @@ const std::string OS::getBashOutput(const char* command) {
}
return std::string(hBuff);
}
else {
pclose(proc);
}
return std::string();
#else
ELPP_UNUSED(command);
Expand Down Expand Up @@ -1260,7 +1266,9 @@ bool CommandLineArgs::hasParamWithValue(const char* paramKey) const {
}

const char* CommandLineArgs::getParamValue(const char* paramKey) const {
return m_paramsWithValue.find(std::string(paramKey))->second.c_str();
std::map<std::string, std::string>::const_iterator i =
m_paramsWithValue.find(std::string(paramKey));
return (i != m_paramsWithValue.end()) ? i->second.c_str() : "";
}

bool CommandLineArgs::hasParam(const char* paramKey) const {
Expand Down
4 changes: 3 additions & 1 deletion src/easylogging++.h
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,9 @@ class Logger : public base::threading::ThreadSafe, public Loggable {
void flush(Level level, base::type::fstream_t* fs);

inline bool isFlushNeeded(Level level) {
return ++m_unflushedCount.find(level)->second >= m_typedConfigurations->logFlushThreshold(level);
std::map<Level,unsigned int>::iterator i = m_unflushedCount.find(level);
return (i != m_unflushedCount.end()) &&
(++(i->second) >= m_typedConfigurations->logFlushThreshold(level));
}

inline LogBuilder* logBuilder(void) const {
Expand Down