Skip to content

Commit 5729923

Browse files
authored
Merge pull request #8538 from douzzer/20250306-Wconversion-fixes-and-tests
20250306-Wconversion-fixes-and-tests
2 parents acc096c + 3ada6e2 commit 5729923

8 files changed

Lines changed: 342 additions & 214 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: wolfCrypt conversion warnings
2+
3+
# START OF COMMON SECTION
4+
on:
5+
push:
6+
branches: [ 'master', 'main', 'release/**' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
# END OF COMMON SECTION
14+
15+
jobs:
16+
build_library:
17+
strategy:
18+
matrix:
19+
config: [
20+
# Add new configs here
21+
'--disable-asm --enable-cryptonly --enable-all-crypto --disable-examples --disable-benchmark --disable-crypttests CPPFLAGS="-Wconversion -Warith-conversion -Wenum-conversion -Wfloat-conversion -Wsign-conversion"',
22+
'--enable-intelasm --enable-cryptonly --enable-all-crypto --disable-examples --disable-benchmark --disable-crypttests CPPFLAGS="-Wconversion -Warith-conversion -Wenum-conversion -Wfloat-conversion -Wsign-conversion"',
23+
'--enable-smallstack --disable-asm --enable-cryptonly --enable-all-crypto --disable-examples --disable-benchmark --disable-crypttests CPPFLAGS="-Wconversion -Warith-conversion -Wenum-conversion -Wfloat-conversion -Wsign-conversion"',
24+
'--enable-smallstack --enable-intelasm --enable-cryptonly --enable-all-crypto --disable-examples --disable-benchmark --disable-crypttests CPPFLAGS="-Wconversion -Warith-conversion -Wenum-conversion -Wfloat-conversion -Wsign-conversion"',
25+
'--enable-cryptonly --enable-all-crypto --disable-examples --disable-benchmark --disable-crypttests CPPFLAGS="-Wconversion -Warith-conversion -Wenum-conversion -Wfloat-conversion -Wsign-conversion -DNO_INT128"'
26+
]
27+
name: build library
28+
if: github.repository_owner == 'wolfssl'
29+
runs-on: ubuntu-22.04
30+
# This should be a safe limit for the tests to run.
31+
timeout-minutes: 6
32+
steps:
33+
- uses: actions/checkout@v4
34+
name: Checkout wolfSSL
35+
36+
- name: Build wolfCrypt with extra type conversion warnings
37+
run: |
38+
./autogen.sh || $(exit 2)
39+
echo "running ./configure ${{ matrix.config }}"
40+
./configure ${{ matrix.config }} || $(exit 3)
41+
make -j 4 || $(exit 4)

wolfcrypt/src/asn.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25321,8 +25321,8 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz,
2532125321
char header[MAX_X509_HEADER_SZ + HEADER_ENCRYPTED_KEY_SIZE];
2532225322
char footer[MAX_X509_HEADER_SZ];
2532325323
#endif
25324-
int headerLen = MAX_X509_HEADER_SZ + HEADER_ENCRYPTED_KEY_SIZE;
25325-
int footerLen = MAX_X509_HEADER_SZ;
25324+
size_t headerLen = MAX_X509_HEADER_SZ + HEADER_ENCRYPTED_KEY_SIZE;
25325+
size_t footerLen = MAX_X509_HEADER_SZ;
2532625326
int i;
2532725327
int err;
2532825328
int outLen; /* return length or error */
@@ -25349,17 +25349,17 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz,
2534925349
#endif
2535025350

2535125351
/* build header and footer based on type */
25352-
XSTRNCPY(header, headerStr, (size_t)headerLen - 1);
25352+
XSTRNCPY(header, headerStr, headerLen - 1);
2535325353
header[headerLen - 2] = 0;
25354-
XSTRNCPY(footer, footerStr, (size_t)footerLen - 1);
25354+
XSTRNCPY(footer, footerStr, footerLen - 1);
2535525355
footer[footerLen - 2] = 0;
2535625356

2535725357
/* add new line to end */
2535825358
XSTRNCAT(header, "\n", 2);
2535925359
XSTRNCAT(footer, "\n", 2);
2536025360

2536125361
#ifdef WOLFSSL_ENCRYPTED_KEYS
25362-
err = wc_EncryptedInfoAppend(header, headerLen, (char*)cipher_info);
25362+
err = wc_EncryptedInfoAppend(header, (int)headerLen, (char*)cipher_info);
2536325363
if (err != 0) {
2536425364
#ifdef WOLFSSL_SMALL_STACK
2536525365
XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
@@ -25369,8 +25369,8 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz,
2536925369
}
2537025370
#endif
2537125371

25372-
headerLen = (int)XSTRLEN(header);
25373-
footerLen = (int)XSTRLEN(footer);
25372+
headerLen = XSTRLEN(header);
25373+
footerLen = XSTRLEN(footer);
2537425374

2537525375
/* if null output and 0 size passed in then return size needed */
2537625376
if (!output && outSz == 0) {
@@ -25384,7 +25384,7 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz,
2538425384
WOLFSSL_ERROR_VERBOSE(err);
2538525385
return err;
2538625386
}
25387-
return headerLen + footerLen + outLen;
25387+
return (int)headerLen + (int)footerLen + outLen;
2538825388
}
2538925389

2539025390
if (!der || !output) {
@@ -25406,14 +25406,14 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz,
2540625406

2540725407
/* header */
2540825408
XMEMCPY(output, header, (size_t)headerLen);
25409-
i = headerLen;
25409+
i = (int)headerLen;
2541025410

2541125411
#ifdef WOLFSSL_SMALL_STACK
2541225412
XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
2541325413
#endif
2541425414

2541525415
/* body */
25416-
outLen = (int)outSz - (headerLen + footerLen); /* input to Base64_Encode */
25416+
outLen = (int)outSz - (int)(headerLen + footerLen); /* input to Base64_Encode */
2541725417
if ( (err = Base64_Encode(der, derSz, output + i, (word32*)&outLen)) < 0) {
2541825418
#ifdef WOLFSSL_SMALL_STACK
2541925419
XFREE(footer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
@@ -25424,7 +25424,7 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz,
2542425424
i += outLen;
2542525425

2542625426
/* footer */
25427-
if ( (i + footerLen) > (int)outSz) {
25427+
if ( (i + (int)footerLen) > (int)outSz) {
2542825428
#ifdef WOLFSSL_SMALL_STACK
2542925429
XFREE(footer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
2543025430
#endif
@@ -25436,7 +25436,7 @@ int wc_DerToPemEx(const byte* der, word32 derSz, byte* output, word32 outSz,
2543625436
XFREE(footer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
2543725437
#endif
2543825438

25439-
return outLen + headerLen + footerLen;
25439+
return outLen + (int)headerLen + (int)footerLen;
2544025440
}
2544125441

2544225442
#endif /* WOLFSSL_DER_TO_PEM */
@@ -25757,7 +25757,7 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
2575725757
}
2575825758

2575925759
#ifdef WOLFSSL_SMALL_STACK
25760-
password = (char*)XMALLOC(passwordSz, heap, DYNAMIC_TYPE_STRING);
25760+
password = (char*)XMALLOC((size_t)passwordSz, heap, DYNAMIC_TYPE_STRING);
2576125761
if (password == NULL) {
2576225762
return MEMORY_E;
2576325763
}

wolfcrypt/src/fe_448.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,56 +1437,56 @@ void fe448_to_bytes(unsigned char* b, const sword32* a)
14371437
b[ 0] = (byte)(in0 >> 0);
14381438
b[ 1] = (byte)(in0 >> 8);
14391439
b[ 2] = (byte)(in0 >> 16);
1440-
b[ 3] = (byte)(in0 >> 24) + (byte)((in1 >> 0) << 4);
1440+
b[ 3] = (byte)((byte)(in0 >> 24) + (byte)((in1 >> 0) << 4));
14411441
b[ 4] = (byte)(in1 >> 4);
14421442
b[ 5] = (byte)(in1 >> 12);
14431443
b[ 6] = (byte)(in1 >> 20);
14441444
b[ 7] = (byte)(in2 >> 0);
14451445
b[ 8] = (byte)(in2 >> 8);
14461446
b[ 9] = (byte)(in2 >> 16);
1447-
b[10] = (byte)(in2 >> 24) + (byte)((in3 >> 0) << 4);
1447+
b[10] = (byte)((byte)(in2 >> 24) + (byte)((in3 >> 0) << 4));
14481448
b[11] = (byte)(in3 >> 4);
14491449
b[12] = (byte)(in3 >> 12);
14501450
b[13] = (byte)(in3 >> 20);
14511451
b[14] = (byte)(in4 >> 0);
14521452
b[15] = (byte)(in4 >> 8);
14531453
b[16] = (byte)(in4 >> 16);
1454-
b[17] = (byte)(in4 >> 24) + (byte)((in5 >> 0) << 4);
1454+
b[17] = (byte)((byte)(in4 >> 24) + (byte)((in5 >> 0) << 4));
14551455
b[18] = (byte)(in5 >> 4);
14561456
b[19] = (byte)(in5 >> 12);
14571457
b[20] = (byte)(in5 >> 20);
14581458
b[21] = (byte)(in6 >> 0);
14591459
b[22] = (byte)(in6 >> 8);
14601460
b[23] = (byte)(in6 >> 16);
1461-
b[24] = (byte)(in6 >> 24) + (byte)((in7 >> 0) << 4);
1461+
b[24] = (byte)((byte)(in6 >> 24) + (byte)((in7 >> 0) << 4));
14621462
b[25] = (byte)(in7 >> 4);
14631463
b[26] = (byte)(in7 >> 12);
14641464
b[27] = (byte)(in7 >> 20);
14651465
b[28] = (byte)(in8 >> 0);
14661466
b[29] = (byte)(in8 >> 8);
14671467
b[30] = (byte)(in8 >> 16);
1468-
b[31] = (byte)(in8 >> 24) + (byte)((in9 >> 0) << 4);
1468+
b[31] = (byte)((byte)(in8 >> 24) + (byte)((in9 >> 0) << 4));
14691469
b[32] = (byte)(in9 >> 4);
14701470
b[33] = (byte)(in9 >> 12);
14711471
b[34] = (byte)(in9 >> 20);
14721472
b[35] = (byte)(in10 >> 0);
14731473
b[36] = (byte)(in10 >> 8);
14741474
b[37] = (byte)(in10 >> 16);
1475-
b[38] = (byte)(in10 >> 24) + (byte)((in11 >> 0) << 4);
1475+
b[38] = (byte)((byte)(in10 >> 24) + (byte)((in11 >> 0) << 4));
14761476
b[39] = (byte)(in11 >> 4);
14771477
b[40] = (byte)(in11 >> 12);
14781478
b[41] = (byte)(in11 >> 20);
14791479
b[42] = (byte)(in12 >> 0);
14801480
b[43] = (byte)(in12 >> 8);
14811481
b[44] = (byte)(in12 >> 16);
1482-
b[45] = (byte)(in12 >> 24) + (byte)((in13 >> 0) << 4);
1482+
b[45] = (byte)((byte)(in12 >> 24) + (byte)((in13 >> 0) << 4));
14831483
b[46] = (byte)(in13 >> 4);
14841484
b[47] = (byte)(in13 >> 12);
14851485
b[48] = (byte)(in13 >> 20);
14861486
b[49] = (byte)(in14 >> 0);
14871487
b[50] = (byte)(in14 >> 8);
14881488
b[51] = (byte)(in14 >> 16);
1489-
b[52] = (byte)(in14 >> 24) + (byte)((in15 >> 0) << 4);
1489+
b[52] = (byte)((byte)(in14 >> 24) + (byte)((in15 >> 0) << 4));
14901490
b[53] = (byte)(in15 >> 4);
14911491
b[54] = (byte)(in15 >> 12);
14921492
b[55] = (byte)(in15 >> 20);

wolfcrypt/src/fe_operations.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ int curve25519(byte* q, const byte* n, const byte* p)
150150
swap = 0;
151151
for (pos = 254;pos >= 0;--pos) {
152152
unsigned int b;
153-
b = n[pos / 8] >> (pos & 7);
153+
b = (unsigned int)(n[pos / 8]) >> (pos & 7);
154154
b &= 1;
155155
swap ^= b;
156156
fe_cswap(x2,x3,(int)swap);

0 commit comments

Comments
 (0)