diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c
index c60936a..c33a987 100644
--- a/src/openvpn/buffer.c
+++ b/src/openvpn/buffer.c
@@ -234,17 +234,16 @@
     if (buf_defined(buf))
     {
         char *ptr = (char *)BEND(buf);
-        int cap = buf_forward_capacity(buf);
+        size_t cap = buf_forward_capacity(buf);
 
         if (cap > 1) /* can write more than \0 */
         {
-            int stat;
             va_list arglist;
             va_start(arglist, format);
-            stat = vsnprintf(ptr, cap, format, arglist);
+            int stat = vsnprintf(ptr, cap, format, arglist);
             va_end(arglist);
             buf->len += (int)strnlen(ptr, cap);
-            if (stat >= 0 && stat < cap)
+            if (stat >= 0 && stat < (int)cap)
             {
                 ret = true;
             }
@@ -257,11 +256,11 @@
 buf_puts(struct buffer *buf, const char *str)
 {
     char *ptr = (char *)BEND(buf);
-    int cap = buf_forward_capacity(buf);
+    size_t cap = buf_forward_capacity(buf);
     if (cap > 1) /* can write more than \0 */
     {
-        int str_len = (int)strlcpy(ptr, str, cap);
-        buf->len += (str_len < cap) ? str_len : cap - 1;
+        size_t str_len = strlcpy(ptr, str, cap);
+        buf->len += (str_len < cap) ? (int)str_len : (int)cap - 1;
     }
 }
 
diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h
index 541f0bd..32b49d3 100644
--- a/src/openvpn/buffer.h
+++ b/src/openvpn/buffer.h
@@ -643,11 +643,6 @@
     return true;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
 /**
  * Initialise a buffer with an externally provided writable memory region.
  *
@@ -660,7 +655,7 @@
  * @param size  Size of the memory region in bytes.
  */
 static inline void
-buf_set_write(struct buffer *buf, uint8_t *data, int size)
+buf_set_write(struct buffer *buf, uint8_t *data, size_t size)
 {
     if (!buf_size_valid(size))
     {
@@ -668,7 +663,7 @@
     }
     buf->len = 0;
     buf->offset = 0;
-    buf->capacity = size;
+    buf->capacity = (int)size;
     buf->data = data;
     if (size > 0 && data)
     {
@@ -1039,7 +1034,7 @@
  * @return Number of bytes available for appending, or 0 if \c buf is
  *         invalid.
  */
-static inline int
+static inline size_t
 buf_forward_capacity(const struct buffer *buf)
 {
     if (buf_valid(buf))
@@ -1049,7 +1044,7 @@
         {
             ret = 0;
         }
-        return ret;
+        return (size_t)ret;
     }
     else
     {
@@ -1252,6 +1247,11 @@
     return true;
 }
 
+#if defined(__GNUC__) || defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wsign-conversion"
+#endif
+
 /**
  * Prepend data to a buffer.
  *
diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index db1cb41..8b4cc3b 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -1825,7 +1825,7 @@
 bool
 generate_ephemeral_key(struct buffer *key, const char *key_name)
 {
-    const int len = BCAP(key);
+    const int len = (int)BCAP(key);
 
     msg(M_INFO, "Using random %s.", key_name);
 
diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c
index 0a1d00c..1246bc6 100644
--- a/src/openvpn/crypto_openssl.c
+++ b/src/openvpn/crypto_openssl.c
@@ -523,7 +523,7 @@
     uint8_t *dst_data = buf_write_alloc(dst, data_read_len);
     if (!dst_data)
     {
-        dmsg(D_CRYPT_ERRORS, "%s: dst too small (%i, needs %li)", __func__, BCAP(dst),
+        dmsg(D_CRYPT_ERRORS, "%s: dst too small (%zu, needs %li)", __func__, BCAP(dst),
              data_read_len);
         goto cleanup;
     }
diff --git a/src/openvpn/push.c b/src/openvpn/push.c
index 6f628b8..eb11107 100644
--- a/src/openvpn/push.c
+++ b/src/openvpn/push.c
@@ -805,7 +805,7 @@
 #endif
 
 static bool
-send_push_options(struct context *c, struct buffer *buf, struct push_list *push_list, int safe_cap,
+send_push_options(struct context *c, struct buffer *buf, struct push_list *push_list, size_t safe_cap,
                   bool *push_sent, bool *multi_push)
 {
     struct push_entry *e = push_list->head;
@@ -820,7 +820,7 @@
                 msg(M_WARN, "--push option is too long");
                 return false;
             }
-            if (BLEN(buf) + (int)l >= safe_cap)
+            if (BLENZ(buf) + l >= safe_cap)
             {
                 buf_printf(buf, ",push-continuation 2");
                 {
@@ -835,7 +835,7 @@
                     buf_printf(buf, "%s", push_reply_cmd);
                 }
             }
-            if (BLEN(buf) + (int)l >= safe_cap)
+            if (BLENZ(buf) + l >= safe_cap)
             {
                 msg(M_WARN, "--push option is too long");
                 return false;
@@ -873,8 +873,8 @@
     struct gc_arena gc = gc_new();
     struct buffer buf = alloc_buf_gc(PUSH_BUNDLE_SIZE, &gc);
     bool multi_push = false;
-    const int extra = 84; /* extra space for possible trailing ifconfig and push-continuation */
-    const int safe_cap = BCAP(&buf) - extra;
+    const size_t extra = 84; /* extra space for possible trailing ifconfig and push-continuation */
+    const size_t safe_cap = BCAP(&buf) - extra;
     bool push_sent = false;
 
     buf_printf(&buf, "%s", push_reply_cmd);
diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c
index 93e67fd..19a2d48 100644
--- a/src/openvpn/ssl_mbedtls.c
+++ b/src/openvpn/ssl_mbedtls.c
@@ -1063,7 +1063,6 @@
 key_state_read_ciphertext(struct key_state_ssl *ks, struct buffer *buf)
 {
     int retval = 0;
-    int len = 0;
 
     ASSERT(NULL != ks);
     ASSERT(buf);
@@ -1074,9 +1073,7 @@
         return 0;
     }
 
-    len = buf_forward_capacity(buf);
-
-    retval = endless_buf_read(&ks->bio_ctx->out, BPTR(buf), len);
+    retval = endless_buf_read(&ks->bio_ctx->out, BPTR(buf), BCAP(buf));
 
     /* Error during read, check for retry error */
     if (retval < 0)
@@ -1148,7 +1145,6 @@
 key_state_read_plaintext(struct key_state_ssl *ks, struct buffer *buf)
 {
     int retval = 0;
-    int len = 0;
 
     ASSERT(NULL != ks);
     ASSERT(buf);
@@ -1159,9 +1155,7 @@
         return 0;
     }
 
-    len = buf_forward_capacity(buf);
-
-    retval = mbedtls_ssl_read(ks->ctx, BPTR(buf), len);
+    retval = mbedtls_ssl_read(ks->ctx, BPTR(buf), BCAP(buf));
 
     /* Error during read, check for retry error */
     if (retval < 0)
diff --git a/src/openvpn/ssl_ncp.c b/src/openvpn/ssl_ncp.c
index df9e42c..7b15f5f 100644
--- a/src/openvpn/ssl_ncp.c
+++ b/src/openvpn/ssl_ncp.c
@@ -154,7 +154,7 @@
             }
 
             /* Ensure buffer has capacity for cipher name + : + \0 */
-            if (buf_forward_capacity(&new_list) < (int)strlen(ovpn_cipher_name) + 2)
+            if (buf_forward_capacity(&new_list) < strlen(ovpn_cipher_name) + 2)
             {
                 msg(M_WARN, "Length of --data-ciphers is over the "
                             "limit of 127 chars");
@@ -563,8 +563,7 @@
     uint8_t *ncp_ciphers = gc_malloc(ncp_ciphers_len, true, &o->gc);
 
     struct buffer ncp_ciphers_buf;
-    ASSERT(ncp_ciphers_len <= INT_MAX);
-    buf_set_write(&ncp_ciphers_buf, ncp_ciphers, (int)ncp_ciphers_len);
+    buf_set_write(&ncp_ciphers_buf, ncp_ciphers, ncp_ciphers_len);
 
     const char *def = strstr(o->ncp_ciphers, search);
 
diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c
index 57ef9f7..30ef383 100644
--- a/src/openvpn/ssl_openssl.c
+++ b/src/openvpn/ssl_openssl.c
@@ -2155,13 +2155,12 @@
          * if the buffer is not empty */
         return 0;
     }
-    int len = buf_forward_capacity(buf);
 
     /*
      * BIO_read brackets most of the serious RSA
      * key negotiation number crunching.
      */
-    int i = BIO_read(bio, BPTR(buf), len);
+    int i = BIO_read(bio, BPTR(buf), (int)BCAP(buf));
 
     VALGRIND_MAKE_READABLE((void *)&i, sizeof(i));
 
diff --git a/src/openvpn/status.c b/src/openvpn/status.c
index 533619f..0a3fc019 100644
--- a/src/openvpn/status.c
+++ b/src/openvpn/status.c
@@ -215,11 +215,6 @@
     return ret;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
 #define STATUS_PRINTF_MAXLEN 512
 
 void
@@ -281,7 +276,7 @@
             if (c == -1)
             {
                 ASSERT(buf_init(&so->read_buf, 0));
-                ssize_t len = read(so->fd, BPTR(&so->read_buf), BCAP(&so->read_buf));
+                ssize_t len = read(so->fd, BPTR(&so->read_buf), (unsigned int)BCAP(&so->read_buf));
                 if (len <= 0)
                 {
                     break;
@@ -311,7 +306,3 @@
 
     return ret;
 }
-
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
diff --git a/src/openvpn/tls_crypt.c b/src/openvpn/tls_crypt.c
index d7f69f7..5617ad3 100644
--- a/src/openvpn/tls_crypt.c
+++ b/src/openvpn/tls_crypt.c
@@ -380,8 +380,8 @@
         msg(M_WARN, "ERROR: could not write tag");
         return false;
     }
-    const int data_len = BLEN(src_metadata) + sizeof(src_key->keys) + sizeof(uint16_t);
-    const int tagged_len = data_len + TLS_CRYPT_TAG_SIZE;
+    const size_t data_len = BLENZ(src_metadata) + sizeof(src_key->keys) + sizeof(uint16_t);
+    const size_t tagged_len = data_len + TLS_CRYPT_TAG_SIZE;
     const uint16_t net_len = htons((uint16_t)tagged_len);
     hmac_ctx_t *hmac_ctx = server_key->hmac;
     hmac_ctx_reset(hmac_ctx);
@@ -396,7 +396,7 @@
     ASSERT(cipher_ctx_reset(cipher_ctx, tag));
 
     /* Overflow check (OpenSSL requires an extra block in the dst buffer) */
-    const int padded_len = data_len + cipher_ctx_block_size(cipher_ctx);
+    const size_t padded_len = data_len + cipher_ctx_block_size(cipher_ctx);
     if (buf_forward_capacity(&work) < padded_len)
     {
         msg(M_WARN, "ERROR: could not crypt: insufficient space in dst");
@@ -735,7 +735,7 @@
         size_t b64_length = strlen(b64_metadata);
         metadata = alloc_buf_gc(OPENVPN_BASE64_DECODED_LENGTH(b64_length) + 1, &gc);
         ASSERT(buf_write(&metadata, &TLS_CRYPT_METADATA_TYPE_USER, 1));
-        int decoded_len = openvpn_base64_decode(b64_metadata, BEND(&metadata), BCAP(&metadata));
+        int decoded_len = openvpn_base64_decode(b64_metadata, BEND(&metadata), (int)BCAP(&metadata));
         if (decoded_len < 0)
         {
             msg(M_FATAL, "ERROR: failed to base64 decode provided metadata");
diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index 0ba8a4a..c56ace3 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -4008,7 +4008,7 @@
  * registry for the TAP device # = device_number.
  */
 static const char *
-get_unspecified_device_guid(const int device_number, uint8_t *actual_name, int actual_name_size,
+get_unspecified_device_guid(const int device_number, uint8_t *actual_name, size_t actual_name_size,
                             const struct tap_reg *tap_reg_src,
                             const struct panel_reg *panel_reg_src,
                             enum tun_driver_type *windows_driver, struct gc_arena *gc)
@@ -4071,7 +4071,7 @@
  * returning the GUID and optional actual_name and device type
  */
 static const char *
-get_device_guid(const char *name, uint8_t *actual_name, int actual_name_size,
+get_device_guid(const char *name, uint8_t *actual_name, size_t actual_name_size,
                 enum tun_driver_type *windows_driver, const struct tap_reg *tap_reg,
                 const struct panel_reg *panel_reg, struct gc_arena *gc)
 {
@@ -6087,8 +6087,9 @@
     {
         struct buffer out = alloc_buf_gc(256, gc);
         DWORD len;
-        if (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_INFO, BSTR(&out), BCAP(&out), BSTR(&out),
-                            BCAP(&out), &len, NULL))
+        if (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_INFO, BSTR(&out),
+                            (DWORD)BCAP(&out), BSTR(&out),
+                            (DWORD)BCAP(&out), &len, NULL))
         {
             return BSTR(&out);
         }
@@ -6103,8 +6104,8 @@
     {
         struct buffer out = alloc_buf(1024);
         DWORD len;
-        while (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_LOG_LINE, BSTR(&out), BCAP(&out),
-                               BSTR(&out), BCAP(&out), &len, NULL))
+        while (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_LOG_LINE, BSTR(&out), (DWORD)BCAP(&out),
+                               BSTR(&out), (DWORD)BCAP(&out), &len, NULL))
         {
             msg(D_TAP_WIN_DEBUG, "TAP-Windows: %s", BSTR(&out));
         }
