Skip to content

fix: properly handle return codes in pack_timestamp#672

Draft
KowalskiThomas wants to merge 1 commit intomsgpack:mainfrom
KowalskiThomas:kowalski/fix-properly-handle-return-codes-in-pack_timestamp
Draft

fix: properly handle return codes in pack_timestamp#672
KowalskiThomas wants to merge 1 commit intomsgpack:mainfrom
KowalskiThomas:kowalski/fix-properly-handle-return-codes-in-pack_timestamp

Conversation

@KowalskiThomas
Copy link
Copy Markdown
Contributor

@KowalskiThomas KowalskiThomas commented May 11, 2026

What is this PR?

This PR makes it so that return codes of helpers called in msgpack_pack_ext are properly checked and surfaced if they're indicative of a failure.

Note the "big" diff at the end of the function is an indentation change on top of the actual change -- the code used to be indented with three spaces instead of four. I changed that (should be clear looking at the diff without whitespace changes).

Comment thread msgpack/pack_template.h
Comment on lines 578 to 589
} else {
/* seconds is signed or >34bits */
unsigned char buf[12];
_msgpack_store32(&buf[0], nanoseconds);
_msgpack_store64(&buf[4], seconds);
msgpack_pack_ext(x, -1, 12);
msgpack_pack_raw_body(x, buf, 12);
/* seconds is signed or >34bits */
unsigned char buf[12];
_msgpack_store32(&buf[0], nanoseconds);
_msgpack_store64(&buf[4], seconds);
ret = msgpack_pack_ext(x, -1, 12);
if (ret != 0)
return ret;

return msgpack_pack_raw_body(x, buf, 12);
}
return 0;
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If this was my code, I would probably prefer doing something like

if (condition) {
  // whatever
  return something;
}

// the contents of the else

to make it clear to the reader that we never not return a value from the function. This is even more relevant now that I've removed the return 0 at the end. But it's not my code so... let me know.

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.

1 participant