Skip to content
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

Merged
merged 1 commit into from
Sep 4, 2024
Merged

Conversation

SparkiDev
Copy link
Contributor

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

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@SparkiDev SparkiDev self-assigned this Aug 29, 2024
@SparkiDev SparkiDev force-pushed the type_conversion_fixes_3 branch from dddcc22 to 910740b Compare August 29, 2024 23:43
@SparkiDev
Copy link
Contributor Author

retest this please

@SparkiDev SparkiDev assigned wolfSSL-Bot and douzzer and unassigned SparkiDev Aug 30, 2024
@SparkiDev SparkiDev requested a review from wolfSSL-Bot August 30, 2024 01:06
Copy link
Contributor

@douzzer douzzer left a 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.)

@@ -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) \
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -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) \
Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -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), \
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -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);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

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

flag != 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}

/* Free pkcs7 resources but not the structure itself */
pkcs7->isDynamic = 0;
wc_PKCS7_Free(pkcs7);
pkcs7->isDynamic = isDynamic;
pkcs7->isDynamic = (isDynamic == 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

isDynamic != 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

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

!= 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

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

!= 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

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

!= 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -8194,13 +8207,15 @@ static int wc_PKCS7_EncryptContent(PKCS7* pkcs7, int encryptOID, byte* key,
ret = wc_AesGcmEncrypt(aes, out, in, inSz, iv, ivSz,
Copy link
Contributor

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,
      |                                                                        ^~~~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@douzzer douzzer assigned SparkiDev and unassigned wolfSSL-Bot Aug 31, 2024
Changes to get compilation with -Wconversion passing on the files.
@SparkiDev SparkiDev force-pushed the type_conversion_fixes_3 branch from 910740b to ed7beb4 Compare September 2, 2024 09:19
@SparkiDev
Copy link
Contributor Author

retest this please

@SparkiDev SparkiDev removed their assignment Sep 2, 2024
@douzzer douzzer merged commit b26fa6c into wolfSSL:master Sep 4, 2024
129 checks passed
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.

3 participants