-
Notifications
You must be signed in to change notification settings - Fork 240
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
Change validation functions to accept output type of ZSTD_getFrameContentSize #285
Change validation functions to accept output type of ZSTD_getFrameContentSize #285
Conversation
…tentSize Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
please run this CI job |
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.
Could we avoid the NOLINT here?
The lint warning is from using Edit: /**
* Checks compression_result and throws a runtime_error if there was a ZSTD error.
* \param compression_result is the return value of ZSTD_decompress.
*/
void throw_on_zstd_error(
const decltype(ZSTD_decompress(nullptr, 0, nullptr, 0)) compression_result
) Be acceptable? |
Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
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.
Nice call with the decltype!
I think you missed a hallway discussion with Thomas; paraphrasing: |
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.
LGTM, consider adding a comment on top of the decltype
just to explain why we have this here.
Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
@@ -34,6 +34,8 @@ constexpr const int kDefaultZstdCompressionLevel = 1; | |||
|
|||
// String constant used to identify ZstdCompressor. | |||
constexpr const char kCompressionIdentifier[] = "zstd"; | |||
// Used as a parameter type in a function that accepts the output of ZSTD_compress. | |||
using ZstdCompressReturnType = decltype(ZSTD_compress(nullptr, 0, nullptr, 0, 0)); |
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.
Maybe use https://en.cppreference.com/w/cpp/types/result_of instead of making a function call.
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.
decltype actually doesn't make a function call! (I'll update with the document stating this)
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.
Never mind. decltype
doesn't invoke anything, but result_of
is better in this situation because you won't need to write the dummy values to "pass" into the ZSTD_compress()
function.
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.
Yeah, I agree, unfortunately I merged this before you commented.
Addresses the same issue to #282.
The root cause of the problem was an implicit conversion from
unsigned long long
tosize_t
(same on x86_64 platforms)Changes
unsigned long long
directly. This is the return type of ZSTD_getFrameContentSizeSigned-off-by: Zachary Michaels zmichaels11@gmail.com