From 70b9063cd24904fd3d0b83173c51fdcf34085967 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Fri, 7 Apr 2017 22:30:13 +0200 Subject: [PATCH] e_os.h: omit PRIu64. 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 (Merged from https://github.com/openssl/openssl/pull/3148) --- apps/enc.c | 4 ++-- apps/s_cb.c | 2 +- apps/s_client.c | 4 ++-- crypto/asn1/x_int64.c | 4 ++-- e_os.h | 17 ++++++----------- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/apps/enc.c b/apps/enc.c index 85182dcac5..b11d553205 100644 --- a/apps/enc.c +++ b/apps/enc.c @@ -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); diff --git a/apps/s_cb.c b/apps/s_cb.c index e0acd51b22..afa306549d 100644 --- a/apps/s_cb.c +++ b/apps/s_cb.c @@ -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); } diff --git a/apps/s_client.c b/apps/s_client.c index 0292e5f87a..299259533e 100644 --- a/apps/s_client.c +++ b/apps/s_client.c @@ -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))); } diff --git a/crypto/asn1/x_int64.c b/crypto/asn1/x_int64.c index d180a3bb3a..e0520ffa2d 100644 --- a/crypto/asn1/x_int64.c +++ b/crypto/asn1/x_int64.c @@ -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 6819271eaa..559bf90048 100644 --- 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) -- 2.25.1