mbedtls: replace macro constant with `CURL_ARRAYSIZE()`
Also move from `int` to `size_t` for index variables.
Closes #19762
diff --git a/lib/vtls/mbedtls_threadlock.c b/lib/vtls/mbedtls_threadlock.c
index 91de9ec..89cc2b7 100644
--- a/lib/vtls/mbedtls_threadlock.c
+++ b/lib/vtls/mbedtls_threadlock.c
@@ -37,17 +37,14 @@
#include "mbedtls_threadlock.h"
-/* number of thread locks */
-#define NUMT 2
-
-/* This array stores the mutexes available to Mbedtls */
-static MBEDTLS_MUTEX_T mutex_buf[NUMT];
+/* This array stores the mutexes available to mbedTLS */
+static MBEDTLS_MUTEX_T mutex_buf[2];
int Curl_mbedtlsthreadlock_thread_setup(void)
{
- int i;
+ size_t i;
- for(i = 0; i < NUMT; i++) {
+ for(i = 0; i < CURL_ARRAYSIZE(mutex_buf); i++) {
#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
if(pthread_mutex_init(&mutex_buf[i], NULL))
return 0; /* pthread_mutex_init failed */
@@ -63,9 +60,9 @@
int Curl_mbedtlsthreadlock_thread_cleanup(void)
{
- int i;
+ size_t i;
- for(i = 0; i < NUMT; i++) {
+ for(i = 0; i < CURL_ARRAYSIZE(mutex_buf); i++) {
#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
if(pthread_mutex_destroy(&mutex_buf[i]))
return 0; /* pthread_mutex_destroy failed */
@@ -78,9 +75,9 @@
return 1; /* OK */
}
-int Curl_mbedtlsthreadlock_lock_function(int n)
+int Curl_mbedtlsthreadlock_lock_function(size_t n)
{
- if(n < NUMT) {
+ if(n < CURL_ARRAYSIZE(mutex_buf)) {
#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
if(pthread_mutex_lock(&mutex_buf[n])) {
DEBUGF(curl_mfprintf(stderr, "Error: "
@@ -98,9 +95,9 @@
return 1; /* OK */
}
-int Curl_mbedtlsthreadlock_unlock_function(int n)
+int Curl_mbedtlsthreadlock_unlock_function(size_t n)
{
- if(n < NUMT) {
+ if(n < CURL_ARRAYSIZE(mutex_buf)) {
#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
if(pthread_mutex_unlock(&mutex_buf[n])) {
DEBUGF(curl_mfprintf(stderr, "Error: "
diff --git a/lib/vtls/mbedtls_threadlock.h b/lib/vtls/mbedtls_threadlock.h
index 9402af6..1855d4c 100644
--- a/lib/vtls/mbedtls_threadlock.h
+++ b/lib/vtls/mbedtls_threadlock.h
@@ -33,8 +33,8 @@
int Curl_mbedtlsthreadlock_thread_setup(void);
int Curl_mbedtlsthreadlock_thread_cleanup(void);
-int Curl_mbedtlsthreadlock_lock_function(int n);
-int Curl_mbedtlsthreadlock_unlock_function(int n);
+int Curl_mbedtlsthreadlock_lock_function(size_t n);
+int Curl_mbedtlsthreadlock_unlock_function(size_t n);
#else