[Rpm-maint] [rpm-software-management/rpm] Use int64_t for lengths (#1492)
Demi Marie Obenour
notifications at github.com
Thu Feb 18 20:51:55 UTC 2021
> All these casts are making my skin crawl. My golden rule is that needing a cast is a warning sign that says to look for another way. I'm in a bit of denial over the need to cast to int64 to ensure the calculation occurs at the target variable type - are todays "smart" optimizing compilers _really_ that dumb? I get the need for such a cast in eg anonymous conditional context, but not when the target variable type is well known such as here.
Sadly it is necessary :disappointed:. That said, there is another option: use GCC and Clang’s overflow-checking builtins, such as `__builtin_mul_overflow`. Those always have well-defined behavior and report overflow, which is what we really want IMO.
Admittedly, `__builtin_mul_overflow` isn’t part of any C standard (though it should be, IMO). However, we use GCC/Clang extensions elsewhere in the code, so I would be fine with this.
> Also the cast on the return is unnecessary, the compiler will do the right thing without our help so let it. The INT_MAX check makes the point clear enough.
That’s fine.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/1492#issuecomment-781626755
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20210218/dd6d45aa/attachment.html>
More information about the Rpm-maint
mailing list