Skip to content

Commit d0fdf62

Browse files
Check whether a pointer created by dynamic_cast is null before using it. (#689)
What I did Check whether a pointer created by dynamic_cast is null before using it. Why I did it dynamic_cast<ConsumerStateTable *>(selectable) may return NULL
1 parent 2cae742 commit d0fdf62

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

common/logger.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,14 @@ void Logger::settingThread()
233233
}
234234

235235
KeyOpFieldsValuesTuple koValues;
236-
dynamic_cast<ConsumerStateTable *>(selectable)->pop(koValues);
236+
ConsumerStateTable *consumerStateTable = NULL;
237+
consumerStateTable = dynamic_cast<ConsumerStateTable *>(selectable);
238+
if (consumerStateTable == NULL)
239+
{
240+
SWSS_LOG_ERROR("dynamic_cast returned NULL");
241+
break;
242+
}
243+
consumerStateTable->pop(koValues);
237244
std::string key = kfvKey(koValues), op = kfvOp(koValues);
238245

239246
if (op != SET_COMMAND || !m_settingChangeObservers.contains(key))

0 commit comments

Comments
 (0)