Skip to content

Commit 1c51465

Browse files
authored
Merge pull request #7627 from douzzer/20240606-clang-tidy-and-mingw-fixes
20240606-clang-tidy-and-mingw-fixes
2 parents d09f955 + ac5caba commit 1c51465

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

src/bio.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ int wolfSSL_BIO_read(WOLFSSL_BIO* bio, void* buf, int len)
312312
ret = (int)XFREAD(buf, 1, (size_t)len, (XFILE)bio->ptr);
313313
}
314314
else {
315-
#if !defined(USE_WINDOWS_API) && !defined(NO_WOLFSSL_DIR) && \
315+
#if defined(XREAD) && !defined(NO_WOLFSSL_DIR) && \
316316
!defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2)
317317
ret = (int)XREAD(bio->num, buf, (size_t)len);
318318
#else
@@ -682,7 +682,7 @@ int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len)
682682
ret = (int)XFWRITE(data, 1, (size_t)len, (XFILE)bio->ptr);
683683
}
684684
else {
685-
#if !defined(USE_WINDOWS_API) && !defined(NO_WOLFSSL_DIR) && \
685+
#if defined(XWRITE) && !defined(NO_WOLFSSL_DIR) && \
686686
!defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2)
687687
ret = (int)XWRITE(bio->num, data, (size_t)len);
688688
#else
@@ -1617,7 +1617,12 @@ int wolfSSL_BIO_write_filename(WOLFSSL_BIO *bio, char *name)
16171617
XFCLOSE((XFILE)bio->ptr);
16181618
}
16191619

1620-
bio->ptr = XFOPEN(name, "w");
1620+
/* 'b' flag is ignored on POSIX targets, but on Windows it assures
1621+
* inhibition of LF<->CRLF rewriting, so that there is consistency
1622+
* between the size and contents of the representation in memory and on
1623+
* disk.
1624+
*/
1625+
bio->ptr = XFOPEN(name, "wb");
16211626
if (((XFILE)bio->ptr) == XBADFILE) {
16221627
return WOLFSSL_FAILURE;
16231628
}

src/ssl.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23701,9 +23701,18 @@ const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
2370123701
const char ap[] = "/.rnd";
2370223702

2370323703
WOLFSSL_MSG("Environment variable RANDFILE not set");
23704+
2370423705
if ((rt = XGETENV("HOME")) == NULL) {
23706+
#ifdef XALTHOMEVARNAME
23707+
if ((rt = XGETENV(XALTHOMEVARNAME)) == NULL) {
23708+
WOLFSSL_MSG("Environment variable HOME and " XALTHOMEVARNAME
23709+
" not set");
23710+
return NULL;
23711+
}
23712+
#else
2370523713
WOLFSSL_MSG("Environment variable HOME not set");
2370623714
return NULL;
23715+
#endif
2370723716
}
2370823717

2370923718
if (len > XSTRLEN(rt) + XSTRLEN(ap)) {
@@ -23713,7 +23722,7 @@ const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
2371323722
return fname;
2371423723
}
2371523724
else {
23716-
WOLFSSL_MSG("HOME too large for buffer");
23725+
WOLFSSL_MSG("Path too large for buffer");
2371723726
return NULL;
2371823727
}
2371923728
}

wolfcrypt/src/port/riscv/riscv-64-aes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ static void wc_aes_ctr_encrypt_asm(Aes* aes, byte* out, const byte* in,
14711471
* @param [in] sz Number of bytes to encrypt.
14721472
* @return 0 on success.
14731473
* @return BAD_FUNC_ARG when aes, out or in is NULL.
1474-
* @return BAD_FUNC_ARG when key size in AES object is not supported.
1474+
* @return BAD_FUNC_ARG when key size in AES object is not supported.
14751475
*/
14761476
int wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
14771477
{
@@ -4231,7 +4231,7 @@ static WC_INLINE void IncrementAesCounter(byte* inOutCtr)
42314231
* @param [in] sz Number of bytes to encrypt.
42324232
* @return 0 on success.
42334233
* @return BAD_FUNC_ARG when aes, out or in is NULL.
4234-
* @return BAD_FUNC_ARG when key size in AES object is not supported.
4234+
* @return BAD_FUNC_ARG when key size in AES object is not supported.
42354235
*/
42364236
int wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
42374237
{

wolfcrypt/src/wc_kyber_poly.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,8 +2785,8 @@ void kyber_decompress_5(sword16* p, const unsigned char* b)
27852785
* @param [in] j Index of bit in byte.
27862786
*/
27872787
#define FROM_MSG_BIT(p, msg, i, j) \
2788-
(p)[8 * (i) + (j)] = (((sword16)0 - (sword16)(((msg)[i] >> (j)) & 1)) ^ \
2789-
kyber_opt_blocker) & KYBER_Q_1_HALF
2788+
((p)[8 * (i) + (j)] = (((sword16)0 - (sword16)(((msg)[i] >> (j)) & 1)) ^ \
2789+
kyber_opt_blocker) & KYBER_Q_1_HALF)
27902790

27912791
/* Convert message to polynomial.
27922792
*

wolfssl/wolfcrypt/wc_port.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,12 +716,16 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
716716
#if !defined(NO_WOLFSSL_DIR)\
717717
&& !defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2)
718718
#if defined(USE_WINDOWS_API)
719+
#include <io.h>
719720
#include <sys/stat.h>
720721
#ifndef XSTAT
721722
#define XSTAT _stat
722723
#endif
723724
#define XS_ISREG(s) (s & _S_IFREG)
724725
#define SEPARATOR_CHAR ';'
726+
#define XWRITE _write
727+
#define XREAD _read
728+
#define XALTHOMEVARNAME "USERPROFILE"
725729

726730
#elif defined(ARDUINO)
727731
#ifndef XSTAT

0 commit comments

Comments
 (0)