Skip to content

Handle Nil values for cbg.Deferred#14

Merged
whyrusleeping merged 1 commit intowhyrusleeping:masterfrom
hannahhoward:feat/deferred-null-check
Apr 2, 2020
Merged

Handle Nil values for cbg.Deferred#14
whyrusleeping merged 1 commit intowhyrusleeping:masterfrom
hannahhoward:feat/deferred-null-check

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