Skip to content
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

Handle Nil values for cbg.Deferred #14

Merged

Conversation

hannahhoward
Copy link
Contributor

Goals

Handle two unusual cases for a cbg.Deferred value in the Marshalling process

Implementation

  • Case: a *cbg.Deferred value is marshaled when the pointer is nil

Resolution: add a self nil check in the Marshall method for *cbg.Deferred and write a cbor.Null

  • Case: a *cbg.Deferred value is not nil but has a Raw field that is nil

Resolution: this shouldn't happen. It means you forgot to serialize the deferred value into Raw. Moreover, currently it produces unpredictable behavior because Marshall will succeed (writing nothing), but then nothing is written to the buffer so if a Deferred is in a struct, the immediate proceeding field will likely have an unpredictable error, as it's data will be read into Raw on Unmarshal. Instead, return error on Marshal for this case.

add a self check for nil in cbg.Deferred. Also add an error check for Deferred.Raw = nil which
causes an error on unmarshal
Copy link
Owner

@whyrusleeping whyrusleeping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@hannahhoward
Copy link
Contributor Author

@whyrusleeping can you merge it? I don't have access :)

@whyrusleeping whyrusleeping merged commit 3d27c14 into whyrusleeping:master Apr 2, 2020
@aschmahmann aschmahmann mentioned this pull request Sep 22, 2020
72 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants