-
Notifications
You must be signed in to change notification settings - Fork 837
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
Type conversion fixes #7918
Type conversion fixes #7918
Conversation
dddcc22
to
910740b
Compare
retest this please |
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.
Good amount of progress here, though of course it would be nicer if we just had self-consistent types in the first place, rather than an armada of casts to support legacy code and API signatures.
checkpoint for the record: on a default build of this PR, I count 150 remaining -Wconversions
in the TLS layer, 39 in api.c
, and 28 in the crypto layer, all but 2 in test.c
. (and I've noted those 2 in my review.)
wolfssl/wolfcrypt/asn.h
Outdated
@@ -670,7 +670,7 @@ WOLFSSL_LOCAL void SetASN_OID(ASNSetData *dataASN, int oid, int oidType); | |||
do { \ | |||
int ii; \ | |||
for (ii = (node) + 1; ii < (int)(dataASNLen); ii++) { \ | |||
if ((asn)[ii].depth <= (asn)[node].depth) \ | |||
if ((asn)[ii].depth <= (asn)[(node)].depth) \ |
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.
[(node)]
not needed -- parens and brackets have the same (highest) associativity, so if [node]
is broken, so is [(node)]
-- but of course [node]
is fine.
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.
fixed
wolfssl/wolfcrypt/asn.h
Outdated
@@ -689,7 +689,7 @@ WOLFSSL_LOCAL void SetASN_OID(ASNSetData *dataASN, int oid, int oidType); | |||
int ii; \ | |||
(dataASN)[node].noOut = 1; \ | |||
for (ii = (node) + 1; ii < (int)(dataASNLen); ii++) { \ | |||
if ((asn)[ii].depth <= (asn)[node].depth) \ | |||
if ((asn)[ii].depth <= (asn)[(node)].depth) \ |
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.
ditto -- and note that if [(node)]
were needed here, it would also be needed a couple lines up (currently L691).
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.
fixed
wolfssl/wolfcrypt/asn.h
Outdated
@@ -594,7 +594,7 @@ WOLFSSL_LOCAL void SetASN_OID(ASNSetData *dataASN, int oid, int oidType); | |||
* @param [in] oidType Type of OID. | |||
*/ | |||
#define SetASN_OID(dataASN, oid, oidType) \ | |||
(dataASN)->data.buffer.data = OidFromId(oid, oidType, \ | |||
(dataASN)->data.buffer.data = OidFromId((oid), (oidType), \ |
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.
parens not needed around values separated by commas -- commas have uniquely minimal associativity.
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.
fixed
wolfcrypt/src/pkcs7.c
Outdated
@@ -819,7 +819,7 @@ int wc_PKCS7_Init(PKCS7* pkcs7, void* heap, int devId) | |||
|
|||
isDynamic = pkcs7->isDynamic; | |||
XMEMSET(pkcs7, 0, sizeof(PKCS7)); | |||
pkcs7->isDynamic = isDynamic; | |||
pkcs7->isDynamic = (isDynamic == 1); |
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.
pedantically & safer, the right RHS construct here is isDynamic != 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.
fixed
wolfcrypt/src/pkcs7.c
Outdated
@@ -3428,7 +3436,7 @@ int wc_PKCS7_SetDetached(PKCS7* pkcs7, word16 flag) | |||
if (pkcs7 == NULL || (flag != 0 && flag != 1)) | |||
return BAD_FUNC_ARG; | |||
|
|||
pkcs7->detached = flag; | |||
pkcs7->detached = (flag == 1); |
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.
flag != 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.
fixed
wolfcrypt/src/pkcs7.c
Outdated
} | ||
|
||
/* Free pkcs7 resources but not the structure itself */ | ||
pkcs7->isDynamic = 0; | ||
wc_PKCS7_Free(pkcs7); | ||
pkcs7->isDynamic = isDynamic; | ||
pkcs7->isDynamic = (isDynamic == 1); |
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.
isDynamic != 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.
fixed
wolfcrypt/src/pkcs7.c
Outdated
@@ -6231,7 +6241,7 @@ static int PKCS7_VerifySignedData(PKCS7* pkcs7, const byte* hashBuf, | |||
} | |||
|
|||
/* Restore content is PKCS#7 flag */ | |||
pkcs7->contentIsPkcs7Type = contentIsPkcs7Type; | |||
pkcs7->contentIsPkcs7Type = (contentIsPkcs7Type == 1); |
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.
!= 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.
fixed
wolfcrypt/src/pkcs7.c
Outdated
@@ -14351,7 +14393,7 @@ int wc_PKCS7_SetStreamMode(PKCS7* pkcs7, byte flag, | |||
return BAD_FUNC_ARG; | |||
} | |||
#ifdef ASN_BER_TO_DER | |||
pkcs7->encodeStream = flag; | |||
pkcs7->encodeStream = (flag == 1); |
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.
!= 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.
fixed
wolfcrypt/src/pkcs7.c
Outdated
@@ -14387,7 +14429,7 @@ int wc_PKCS7_SetNoCerts(PKCS7* pkcs7, byte flag) | |||
if (pkcs7 == NULL) { | |||
return BAD_FUNC_ARG; | |||
} | |||
pkcs7->noCerts = flag; | |||
pkcs7->noCerts = (flag == 1); |
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.
!= 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.
fixed
wolfcrypt/src/pkcs7.c
Outdated
@@ -8194,13 +8207,15 @@ static int wc_PKCS7_EncryptContent(PKCS7* pkcs7, int encryptOID, byte* key, | |||
ret = wc_AesGcmEncrypt(aes, out, in, inSz, iv, ivSz, |
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.
I'm seeing
wolfcrypt/src/pkcs7.c:8207:62: error: conversion to 'word32' {aka 'unsigned int'} from 'int' may change the sign of the result [-Werror=sign-conversion]
8207 | ret = wc_AesGcmEncrypt(aes, out, in, inSz, iv, ivSz,
| ^~~~
wolfcrypt/src/pkcs7.c:8207:72: error: conversion to 'word32' {aka 'unsigned int'} from 'int' may change the sign of the result [-Werror=sign-conversion]
8207 | ret = wc_AesGcmEncrypt(aes, out, in, inSz, iv, ivSz,
| ^~~~
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.
fixed
Changes to get compilation with -Wconversion passing on the files.
910740b
to
ed7beb4
Compare
retest this please |
Description
Changes to get compilation with -Wconversion passing on the files.
Testing
./configure --disable-shared --enable-all CFLAGS=-Wconversion
Compile the files changed only.
Checklist