-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Fix signed-to-unsigned integer conversion warning in X.509 module #2213
Fix signed-to-unsigned integer conversion warning in X.509 module #2213
Conversation
@sbutcher-arm CI failure due to known fragmentation bug in old version of GnuTLS. |
If the intention was to get all
Another possibility might be |
This is a trivial fix, but if it has a Github issue, it should really have a ChangeLog entry. |
@sbutcher-arm Ok. |
This breaks the buildbot CI on the Visual Studio build. (See: 'any - polarssl_win32 (msvc12_64_make) Build #126'). Log extract:
Demoting the PR to needs work. |
@hanno-arm - I would suggest it's best to adopt @irwir's suggestion of:
|
@sbutcher-arm For uniformity with the rest of the code, I will follow @rahmanih's suggestion of using |
MSVC warns about use of unary `-` operator on unsigned integers.
1b6d2b2
d717c51
to
1b6d2b2
Compare
@AndrzejKurek @mpg Could you please re-review? |
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
Good style would be to avoid type casts; particularly when a cast relies on internal representation of values. |
@irwir That's true for |
For example, in MSVC/x86 |
@irwir |
@hanno-arm
Sorry, I could not get this pharase about padding. Is this stated in C statdard? |
@irwir Yes, Some comments:
I disagree. What should be avoided are reinterpretation casts, i.e. such which take an internal presentation of a value of one type and view it as the representation of another type. Unless the standard mandates the internal presentation, this leads to nonportable code. Casts such as In regards to your suggestion Finally, I was wrong saying that In summary: valid ( := portable ) options are |
@hanno-arm, thanks for the answer. Padding bits are a) optional; b) non-existent in most cases (7.18.1.3); and c) irrelevant because it does not change the value itself (as you mentioned).
Quick look at the code in x509_crt.c suggests, that
Will
Edited out several incorrect statements. |
Hi @irwir,
No, it won't be true regardless of the unsigned integer type you take, because
No, it's not a trick that might or might not work depending on the C implementation - it's behavior entirely defined by the standard: The conversion |
@irwir Your point would apply to code like |
I think the C standard defines very well what this operation (I disagree with calling it a trick) does.
(Regarding casts, I fully agree with what Hanno wrote about the difference between unsafe reinterpret casts and safe static casts.) |
@hanno-arm
@mpg |
@AndrzejKurek Could you please re-review? |
Ping @sbutcher-arm for gatekeeping. |
Fixes #2212.