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 nil check in code-gen converter for binary #693
Conversation
removed proprietary link, please describe the problem in a general way and not using specific proprietary links. |
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.
make a change for nits and description of the bug. approving it.
@@ -808,6 +808,9 @@ func (c *TypeConverter) genStructConverter( | |||
} | |||
case *compile.BinarySpec: | |||
// TODO: handle override. Check if binarySpec can be optional. | |||
for _, line := range checkOptionalNil(indent, c.uninitialized, toIdentifier, prevKeyPrefixes, c.useRecurGen) { |
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.
nit: remove a todo above since its now handled.
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.
Done.
The problem:
Converter doesn't check nil for binary type. So when it tries to convert binary to a nested field, for example out.NestedTwo.Two, it can cause NPEs. Without this fix, it can generate code like the following, while out.NestedTwo can be nil.
The fix:
Add nil check for binary type.
Testing:
Added test, failed and got:
Added code, test passed and got