Check whether a pointer created by dynamic_cast is null before using it.#689
Conversation
|
Hi~ could you please review, thanks. @prsunny @qiluo-msft |
|
please review, thanks. @prsunny @qiluo-msft |
| } | ||
|
|
||
| KeyOpFieldsValuesTuple koValues; | ||
| dynamic_cast<ConsumerStateTable *>(selectable)->pop(koValues); |
There was a problem hiding this comment.
The expression dynamic_cast T(v) converts the expression v to type T. Type T must be a pointer or reference to a complete class type or a pointer to void. If T is a pointer and the dynamic_cast operator fails, the operator returns a null pointer of type T. If T is a reference and the dynamic_cast operator fails, the operator throws the exception std::bad_cast. You can find this class in the standard library header .
In C++ usage, it would be a problem.
It will not be triggered by the test case.
There was a problem hiding this comment.
Totally understood what you are saying. My point is that it could not happen due to the function context. Then assert is the recommendation, no need to check in runtime.
There was a problem hiding this comment.
All right, I have changed the error handling.
I think it is necessary to add this judgment to increase system stability.
There was a problem hiding this comment.
It does add value since the logic will guarantee consumerStateTable != NULL. The extra preventative is okay, then you need to add SWSS_LOG_ERROR to explain, and break instead of continue.
There was a problem hiding this comment.
I have changed. Please review. thanks.
|
Please review, thanks. @qiluo-msft |
|
Could you please merge, thanks. @qiluo-msft |
|
Pending on PR checkers passing. |
|
I changed file to rerun the failed jobs, could you please review and merge. Thanks! @qiluo-msft |
Update sonic-swss-common submodule pointer to include the following: * abda263 Make the loglevel persistent by moving the LOGGER table from the LOGLEVEL DB to the CONFIG DB ([sonic-net#687](sonic-net/sonic-swss-common#687)) * d0fdf62 Check whether a pointer created by dynamic_cast is null before using it. ([sonic-net#689](sonic-net/sonic-swss-common#689)) * 2cae742 [Fast/Warm restart] Implement helper class for waiting restart done ([sonic-net#691](sonic-net/sonic-swss-common#691)) Signed-off-by: dprital <[email protected]>
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