e_os.h: omit PRIu64.
authorAndy Polyakov <appro@openssl.org>
Fri, 7 Apr 2017 20:30:13 +0000 (22:30 +0200)
committerAndy Polyakov <appro@openssl.org>
Sat, 8 Apr 2017 18:35:34 +0000 (20:35 +0200)
PRIu64 is error-prone with BIO_printf, so introduce and stick to custom
platform-neutral macro. 'll' allows to print 64-bit values on *all*
supported platforms, but it's problematic with -Wformat -Werror. Hence
use 'l' in identifiable LP64 cases.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3148)

apps/enc.c
apps/s_cb.c
apps/s_client.c
crypto/asn1/x_int64.c
e_os.h

index 85182dcac58b7f428fd8cccc602123047e3c1438..b11d553205d7e4d87711376fc751ed0f08e8ac11 100644 (file)
@@ -548,8 +548,8 @@ int enc_main(int argc, char **argv)
 
     ret = 0;
     if (verbose) {
-        BIO_printf(bio_err, "bytes read   :%8"PRIu64"\n", BIO_number_read(in));
-        BIO_printf(bio_err, "bytes written:%8"PRIu64"\n", BIO_number_written(out));
+        BIO_printf(bio_err, "bytes read   :%8"BIO_PRI64"u\n", BIO_number_read(in));
+        BIO_printf(bio_err, "bytes written:%8"BIO_PRI64"u\n", BIO_number_written(out));
     }
  end:
     ERR_print_errors(bio_err);
index e0acd51b22b67797a2aee2f3981a737cc887f87c..afa306549d8f6c82f93e64b139045bac98af7966 100644 (file)
@@ -1002,7 +1002,7 @@ static char *hexencode(const unsigned char *data, size_t len)
     int ilen = (int) outlen;
 
     if (outlen < len || ilen < 0 || outlen != (size_t)ilen) {
-        BIO_printf(bio_err, "%s: %" PRIu64 "-byte buffer too large to hexencode\n",
+        BIO_printf(bio_err, "%s: %"BIO_PRI64"u-byte buffer too large to hexencode\n",
                    opt_getprog(), (uint64_t)len);
         exit(1);
     }
index 0292e5f87aa5f4411a744bbf9feace1be9a399c0..299259533e21810a4c6abcf53f12bd276e84f92c 100644 (file)
@@ -2615,8 +2615,8 @@ static void print_stuff(BIO *bio, SSL *s, int full)
 #endif
 
         BIO_printf(bio,
-                   "---\nSSL handshake has read %" PRIu64
-                   " bytes and written %" PRIu64 " bytes\n",
+                   "---\nSSL handshake has read %"BIO_PRI64"u"
+                   " bytes and written %"BIO_PRI64"u bytes\n",
                    BIO_number_read(SSL_get_rbio(s)),
                    BIO_number_written(SSL_get_wbio(s)));
     }
index d180a3bb3ac08490cbbebaed3df96e81183b3a38..e0520ffa2de31e70db936b7e559e2b93ad236227 100644 (file)
@@ -79,8 +79,8 @@ static int uint64_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it,
                         int indent, const ASN1_PCTX *pctx)
 {
     if ((it->size & INTxx_FLAG_SIGNED) == INTxx_FLAG_SIGNED)
-        return BIO_printf(out, "%jd\n", *(int64_t *)pval);
-    return BIO_printf(out, "%ju\n", *(uint64_t *)pval);
+        return BIO_printf(out, "%"BIO_PRI64"d\n", *(int64_t *)pval);
+    return BIO_printf(out, "%"BIO_PRI64"u\n", *(uint64_t *)pval);
 }
 
 /* 32-bit variants */
diff --git a/e_os.h b/e_os.h
index 6819271eaae505f9fb660c176025723a6ef4e6f2..559bf90048dcc6cbbedab99385a87311127f8330 100644 (file)
--- a/e_os.h
+++ b/e_os.h
@@ -30,18 +30,13 @@ extern "C" {
 # endif
 
 /*
- * We need a format operator for some client tools for uint64_t.  If inttypes.h
- * isn't available or did not define it, just go with hard-coded.
+ * BIO_printf format modifier for [u]int64_t.
  */
-# if defined(OPENSSL_SYS_UEFI)
-#  define PRIu64 "Lu"
-# endif
-# ifndef PRIu64
-#  ifdef SIXTY_FOUR_BIT_LONG
-#   define PRIu64 "lu"
-#  else
-#   define PRIu64 "llu"
-#  endif
+# if defined(__LP64__) || (defined(__SIZEOF_LONG__) && __SIZEOF_LONG__==8)
+#  define BIO_PRI64 "l"     /* 'll' does work "universally", but 'l' is
+                             * here to shut -Wformat warnings in LP64... */
+# else
+#  define BIO_PRI64 "ll"
 # endif
 
 # if !defined(NDEBUG) && !defined(OPENSSL_NO_STDIO)