-
Notifications
You must be signed in to change notification settings - Fork 265
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
Check whether a pointer created by dynamic_cast is null before using it. #689
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 |
@@ -233,7 +233,13 @@ void Logger::settingThread() | |||
} | |||
|
|||
KeyOpFieldsValuesTuple koValues; | |||
dynamic_cast<ConsumerStateTable *>(selectable)->pop(koValues); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <drorp@nvidia.com>
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