From 2d905f6715453034d1f942a0237b0d2b9d57326c Mon Sep 17 00:00:00 2001 From: Pauli Date: Thu, 20 Jun 2019 11:24:17 +1000 Subject: Print thread IDs nicely. Remove the union that effectively cast thread IDs to long integers before display and instead print a hex dump of the entire object. Refer #9191 Reviewed-by: Richard Levitte (Merged from https://github.com/openssl/openssl/pull/9194) --- apps/openssl.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'apps/openssl.c') diff --git a/apps/openssl.c b/apps/openssl.c index 7a490cc455..d6820a191e 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -130,11 +130,8 @@ static size_t internal_trace_cb(const char *buf, size_t cnt, { int ret = 0; tracedata *trace_data = vdata; - union { - CRYPTO_THREAD_ID tid; - unsigned long ltid; - } tid; - char buffer[256]; + char buffer[256], *hex; + CRYPTO_THREAD_ID tid; switch (cmd) { case OSSL_TRACE_CTRL_BEGIN: @@ -142,11 +139,11 @@ static size_t internal_trace_cb(const char *buf, size_t cnt, return 0; trace_data->ingroup = 1; - tid.ltid = 0; - tid.tid = CRYPTO_THREAD_get_current_id(); - - BIO_snprintf(buffer, sizeof(buffer), "TRACE[%lx]:%s: ", tid.ltid, - OSSL_trace_get_category_name(category)); + tid = CRYPTO_THREAD_get_current_id(); + hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid)); + BIO_snprintf(buffer, sizeof(buffer), "TRACE[%s]:%s: ", + hex, OSSL_trace_get_category_name(category)); + OPENSSL_free(hex); BIO_ctrl(trace_data->bio, PREFIX_CTRL_SET_PREFIX, strlen(buffer), buffer); break; -- cgit v1.2.3