Browse code

Avoid format specifier %zu for Windows compatibility

- Replace %zu by %u and cast the size_t variable to (unsigned int). The
cast should be safe as in all instances the number involved is small.

Note: mingw64 targets msvcrt.dll runtime that doesn't support %zu and
print "zu" instead of the number. With -Wformat the compiler
does warn that z is an unknown conversion type.

v2: Cast to (unsigned int) instead of (int).

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <1470956309-31268-1-git-send-email-selva.nair@gmail.com>
URL: https://sourceforge.net/p/openvpn/mailman/message/35274787/
Signed-off-by: David Sommerseth <davids@openvpn.net>

Selva Nair authored on 2016/08/12 07:58:29
Showing 3 changed files
... ...
@@ -738,8 +738,8 @@ crypto_adjust_frame_parameters(struct frame *frame,
738 738
 
739 739
   frame_add_to_extra_frame (frame, crypto_overhead);
740 740
 
741
-  msg(D_MTU_DEBUG, "%s: Adjusting frame parameters for crypto by %zu bytes",
742
-      __func__, crypto_overhead);
741
+  msg(D_MTU_DEBUG, "%s: Adjusting frame parameters for crypto by %u bytes",
742
+      __func__, (unsigned int) crypto_overhead);
743 743
 }
744 744
 
745 745
 size_t
... ...
@@ -2992,7 +2992,7 @@ calc_options_string_link_mtu(const struct options *o, const struct frame *frame)
2992 2992
 	  o->replay, cipher_kt_mode_ofb_cfb (fake_kt.cipher));
2993 2993
       frame_finalize(&fake_frame, o->ce.link_mtu_defined, o->ce.link_mtu,
2994 2994
             o->ce.tun_mtu_defined, o->ce.tun_mtu);
2995
-      msg (D_MTU_DEBUG, "%s: link-mtu %zu -> %d", __func__, link_mtu,
2995
+      msg (D_MTU_DEBUG, "%s: link-mtu %u -> %d", __func__, (unsigned int) link_mtu,
2996 2996
 	  EXPANDED_SIZE (&fake_frame));
2997 2997
       link_mtu = EXPANDED_SIZE (&fake_frame);
2998 2998
     }
... ...
@@ -3061,7 +3061,7 @@ options_string (const struct options *o,
3061 3061
    */
3062 3062
 
3063 3063
   buf_printf (&out, ",dev-type %s", dev_type_string (o->dev, o->dev_type));
3064
-  buf_printf (&out, ",link-mtu %zu", calc_options_string_link_mtu(o, frame));
3064
+  buf_printf (&out, ",link-mtu %u", (unsigned int) calc_options_string_link_mtu(o, frame));
3065 3065
   buf_printf (&out, ",tun-mtu %d", PAYLOAD_SIZE (frame));
3066 3066
   buf_printf (&out, ",proto %s",  proto_remote (o->ce.proto, remote));
3067 3067
 
... ...
@@ -1111,8 +1111,8 @@ print_details (struct key_state_ssl * ks_ssl, const char *prefix)
1111 1111
   cert = mbedtls_ssl_get_peer_cert (ks_ssl->ctx);
1112 1112
   if (cert != NULL)
1113 1113
     {
1114
-      openvpn_snprintf (s2, sizeof (s2), ", %zu bit key",
1115
-	  mbedtls_pk_get_bitlen (&cert->pk));
1114
+      openvpn_snprintf (s2, sizeof (s2), ", %u bit key",
1115
+	  (unsigned int) mbedtls_pk_get_bitlen (&cert->pk));
1116 1116
     }
1117 1117
 
1118 1118
   msg (D_HANDSHAKE, "%s%s", s1, s2);