From patchwork Fri Apr 12 07:33:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 788254 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp590699wrm; Fri, 12 Apr 2024 00:35:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWzf0mS/1Pdq+Mybt0iY32I/DZOALsHLRpVlN7en+hNR20149sAl8KTEa4q1x3KcEtCg6bvIbZDq58KpKjX/Tjy X-Google-Smtp-Source: AGHT+IHFlNuKusJw4L0FINPG6xeKYLTBD94If8FQxri4GnCTlMPEQkTZZ/IzbgAZBuhtC+V6EAZi X-Received: by 2002:a0c:dd8f:0:b0:699:406d:9030 with SMTP id v15-20020a0cdd8f000000b00699406d9030mr2082927qvk.38.1712907313278; Fri, 12 Apr 2024 00:35:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712907313; cv=none; d=google.com; s=arc-20160816; b=oPraXP6tfEMI2rzyICxdXIno+P3Ijgc0Jf6OSV6n2XH+tZEO7FkhuyTOn58zYkZtBB rbM1G64JUT8d6bdafmHJa3vUd+EsmUZkwkzL2iSgccXyFN60nTH9RV/obWAIhmhEUw02 a1nTJmJDEh60f5vm3OZ6UqgYNGA7fgTUwM8zPvQBUXtwG7ag7RpiZ33MzXaMFkDbPtMj xyccKjfzNoXjTaf27JBVOPzAN1vhOc0Ahge3KBRdO9yfTs0+uggdbC8WqGv1KuxLKwAN utQ1BaXqbHbB0pRj2ack2itmyWlKY9p9DReJPewX2MMcYIswaFxsBXWMqEUNoUg/cMll MAZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+7uXdJXbZvFgUDV/6dLp0dNk/3VKiyesi33hYvTO4ao=; fh=jZ3p54AjrOULBe9UxOUKEqL9GOupA8QOIQHPSzacviQ=; b=UFvNikgyGnhQ2/SR5/3s8l73jqCajwJPE96jkuAWV62m5xbirO8mfosjukTjUOp/nZ 63KY7je+RokuT85qV4sDDp/zFAr/B+uGVvUJHD4FVO1PDF4xFFvr424/0/uTr9uKs0d/ zYZKZiuzC93gH9heUJDxXbUBZ+dH68qcZfZ8EOkFuO1/hJw4ooDIaVUbco3ULuHtT83b 7d1LfAYsqW/9Pzy8V0xkr9yoljIc2vzSDCiecgchvMpcjspotW4BF/jkiIvLDQ/4OAav +1iCHOBNwObalV9FwEDNGIF6i3C+RdQVphmV+w1lKlZm73RiRiJKbDqH9KmbffAvuJlE 9T2A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GcSJtibv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ne1-20020a056214424100b006993eecb931si3092903qvb.601.2024.04.12.00.35.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Apr 2024 00:35:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GcSJtibv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rvBQJ-00075K-OM; Fri, 12 Apr 2024 03:34:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rvBQC-00071a-0U for qemu-devel@nongnu.org; Fri, 12 Apr 2024 03:34:04 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rvBQ5-000797-O0 for qemu-devel@nongnu.org; Fri, 12 Apr 2024 03:34:02 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1e5b6e8f662so1413895ad.0 for ; Fri, 12 Apr 2024 00:33:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712907236; x=1713512036; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+7uXdJXbZvFgUDV/6dLp0dNk/3VKiyesi33hYvTO4ao=; b=GcSJtibv9rodPYdW6Y516ABbpRY5FWgJhv0J+olKvlxdW3H0wOOcjldEAAorJU+nBA xmA1gGRZh7RGVgmV7+PUOfU0QpGKlQSYVTrPWVQF7crgpgUal8M0C+5RCQav4Fo2c4WV hySv6crQTK5p1a5+xkkWhuc7gJpRie7lm4a8xZsvKGgUnXptFCsn8saEx7eVFtWkKPsd XBijoPHbjSQvlB+AFptewFzgwv0noF0IpRnH7mqK4qWYJS2N/w9l/UundvD4DFcG1vZG jvCYBuWaHkb9BCycS636Cn859AG8CzymIQdn9W2dT7qDPAYwb9+1HhqqrWzhV8WxPZND 0bGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712907236; x=1713512036; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+7uXdJXbZvFgUDV/6dLp0dNk/3VKiyesi33hYvTO4ao=; b=TmNTkxy6iLyD0ActzZ1jkUJbAuEbNpOmjo9fM+F+YwMOSX5v4CohxHPStNq+7sQDb5 qYkaoWLRB8r8Rmb2sGeG1ghcU1OynCJ9zUDUJfmNrNcNFUuVYL13BA8DefK179sH8Lun zHor5uvkRdSr4fWkfxiNqCcLoGbQvCg17Q4td9yTxiUB9sL77K+i0LkaA0wFN1MOmPV1 1kP76AXoYrl0zX/4ZpKCqt5/pjz2cQwHHdTBW2cup+bzLZ4kD9X9dLBvEewDsWB0acbS uZa7ooAB/QNZRthSFLzsvAB56ogJV+5KUp3uUpguJ4hTMYM33XWvgtsOfNd7gwJkZ4Je yegg== X-Gm-Message-State: AOJu0Yxojar7JS96yv+gdSeF+gPOKLUCaB+Ob7CQLwSr6iP6fz1oGgpm yVt+6Mc2NuOxPb43birQncgc4wgkPgbiaV2RAvdg1rbTLSAMqKQD43EBdFpY7wAzmv6dD1sCYTr R X-Received: by 2002:a17:902:eb87:b0:1e4:12e1:88bc with SMTP id q7-20020a170902eb8700b001e412e188bcmr2498786plg.11.1712907236483; Fri, 12 Apr 2024 00:33:56 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id e5-20020a17090301c500b001e556734814sm2206099plh.134.2024.04.12.00.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 00:33:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefan Berger Subject: [PATCH v3 11/27] backends/tpm: Use qemu_hexdump_line to avoid sprintf Date: Fri, 12 Apr 2024 00:33:30 -0700 Message-Id: <20240412073346.458116-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412073346.458116-1-richard.henderson@linaro.org> References: <20240412073346.458116-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1. Using qemu_hexdump_line both fixes the deprecation warning and simplifies the code base. Reviewed-by: Stefan Berger Signed-off-by: Philippe Mathieu-Daudé [rth: Keep the linebreaks every 16 bytes] Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- backends/tpm/tpm_util.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/backends/tpm/tpm_util.c b/backends/tpm/tpm_util.c index 1856589c3b..bf3378fbbe 100644 --- a/backends/tpm/tpm_util.c +++ b/backends/tpm/tpm_util.c @@ -21,6 +21,7 @@ #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "qapi/visitor.h" #include "tpm_int.h" @@ -336,27 +337,22 @@ void tpm_sized_buffer_reset(TPMSizedBuffer *tsb) void tpm_util_show_buffer(const unsigned char *buffer, size_t buffer_size, const char *string) { - size_t len, i; - char *line_buffer, *p; + g_autoptr(GString) str = NULL; + size_t len, i, l; if (!trace_event_get_state_backends(TRACE_TPM_UTIL_SHOW_BUFFER)) { return; } len = MIN(tpm_cmd_get_size(buffer), buffer_size); - /* - * allocate enough room for 3 chars per buffer entry plus a - * newline after every 16 chars and a final null terminator. - */ - line_buffer = g_malloc(len * 3 + (len / 16) + 1); - - for (i = 0, p = line_buffer; i < len; i++) { - if (i && !(i % 16)) { - p += sprintf(p, "\n"); + for (i = 0; i < len; i += l) { + if (str) { + g_string_append_c(str, '\n'); } - p += sprintf(p, "%.2X ", buffer[i]); + l = MIN(len, 16); + str = qemu_hexdump_line(str, buffer, l, 1, 0); } - trace_tpm_util_show_buffer(string, len, line_buffer); - g_free(line_buffer); + g_string_ascii_up(str); + trace_tpm_util_show_buffer(string, len, str->str); }