-
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
Merged
qiluo-msft
merged 12 commits into
sonic-net:master
from
pettershao-ragilenetworks:pettershao-ragilenetworks-patch-1
Oct 24, 2022
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f437c47
Update logger.cpp
pettershao-ragilenetworks 222d457
Update logger.cpp
pettershao-ragilenetworks 599300e
Update logger.cpp
pettershao-ragilenetworks e24f375
Update logger.cpp
pettershao-ragilenetworks f89ff33
Update logger.cpp
pettershao-ragilenetworks dca8229
Update logger.cpp
pettershao-ragilenetworks a9e7bba
Update logger.cpp
pettershao-ragilenetworks 1130c0b
Update logger.cpp
pettershao-ragilenetworks d697a02
Update logger.cpp
pettershao-ragilenetworks 9768308
Update logger.cpp
pettershao-ragilenetworks 022ff37
Update logger.cpp
pettershao-ragilenetworks bb43f05
rerun failed job
pettershao-ragilenetworks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think it is always of the type
ConsumerStateTable
? Did you have a use case to trigger a negative case? If yes, could you add a unit test case?If I understand it correctly, then you can add
assert
. #ClosedThere 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 addSWSS_LOG_ERROR
to explain, andbreak
instead ofcontinue
.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.