From patchwork Wed May 5 17:00:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12240621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA102C433B4 for ; Wed, 5 May 2021 17:12:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1CC5C611AC for ; Wed, 5 May 2021 17:12:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1CC5C611AC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:34328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leL4k-0000tC-V3 for qemu-devel@archiver.kernel.org; Wed, 05 May 2021 13:12:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leKts-0006Aj-Oh for qemu-devel@nongnu.org; Wed, 05 May 2021 13:01:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21906) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leKth-0002QN-BL for qemu-devel@nongnu.org; Wed, 05 May 2021 13:01:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620234075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v6dDjUUr1jX0kd69bV9ZwwKe4Jn9sJZazvtpBwyg5KA=; b=HuHPjlRmvOXoIAX9OjGApArBBrEAjpV5zWBeIxMyZMV0MYi8Kktd/+DxkBPU76FJX1Aprf 2NX2QcFfUoi4pjCctKKRH4qNu7FyTkMT/zqhaUhGNIurIGDjRndIh1TzwteHF+gZFcGzyv wbqOb3ILmSxf9bPMa9kRIc27eD1SgPc= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-5-pIVsGVS3P7Cvu4XR43clhA-1; Wed, 05 May 2021 13:01:13 -0400 X-MC-Unique: pIVsGVS3P7Cvu4XR43clhA-1 Received: by mail-wr1-f70.google.com with SMTP id l2-20020adf9f020000b029010d6bb7f1cbso948418wrf.7 for ; Wed, 05 May 2021 10:01:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v6dDjUUr1jX0kd69bV9ZwwKe4Jn9sJZazvtpBwyg5KA=; b=n1xBmvuXtYyQDO9Qhvzb3SxVcDhZ5McKOAXSy38MnML7qS+t/k6MhFktK9Tp0HgmgX c1F/gsZ3iKaPim/La2SrnpnuhUdLoJNiCeL334SlkO4A8mzdk9IrodlBh3Zohk8GhTIg Dm2gA6QBIGdovAwO+mFMWnX75SCfBkow7JG/QM6FpsUbOxxZvlSKPnOB7LjusvkVUyRM raPGttmmlBWjWUodOZ/VruZanNKcTnkneGITj11MXj4pJQnw6v6vUHU8sa+IN1eG546h xwb2UInaOBhfgntZZisMFBN51ELcN5GbXxboWzgraQYXRR2wbPHtY7YIFmDJsX/tA8dU OPjA== X-Gm-Message-State: AOAM530btwd49UTcoCpZO6fppwjYsb8Sx5jGdOPyt0/aLuuJ9AtoLnK/ Yhzom0DpgcKnRWqcJD8OfbNeWIWlvAOJyzttQP0iGi+hwJMlTI4nmfevnmR4sCvNETHklpVhMFE kJfY32KvldK2/FScJHy0op5ct9SlPysTKoTxEk/Fb0FPN+4Li+l7tcSvKIQ8Se/KW X-Received: by 2002:a5d:4cce:: with SMTP id c14mr12205wrt.29.1620234071948; Wed, 05 May 2021 10:01:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUVOp3pO1Wn/Eg12ZEK46NsmpT3zPU6R7yIqJ0Q6XmSE4diSFvuXPe8REXrt2tEMJBnmTrMA== X-Received: by 2002:a5d:4cce:: with SMTP id c14mr12167wrt.29.1620234071681; Wed, 05 May 2021 10:01:11 -0700 (PDT) Received: from x1w.redhat.com (astrasbourg-653-1-188-220.w90-13.abo.wanadoo.fr. [90.13.127.220]) by smtp.gmail.com with ESMTPSA id n5sm16047652wrx.31.2021.05.05.10.01.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 May 2021 10:01:11 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 3/5] gdbstub: Use fixed-size array in GdbCmdParseEntry instead of pointer Date: Wed, 5 May 2021 19:00:53 +0200 Message-Id: <20210505170055.1415360-4-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210505170055.1415360-1-philmd@redhat.com> References: <20210505170055.1415360-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.693, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kyle Evans , Greg Kurz , =?utf-8?q?A?= =?utf-8?q?lex_Benn=C3=A9e?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Warner Losh , David Gibson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" GdbCmdParseEntry should have enough room with 20 chars for the command string, and 8 for the schema. Add the GDB_CMD_PARSE_ENTRY_CMD_SIZE and GDB_CMD_PARSE_ENTRY_SCHEMA_SIZE definitions. Do not use pointer to string of unknown length, but array of fixed size. Having constant size will help use to remove the alloca() call in process_string_cmd() in the next commit. Signed-off-by: Philippe Mathieu-Daudé --- gdbstub.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 6f663cbd8dd..0d5569ee539 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1457,11 +1457,13 @@ typedef void (*GdbCmdHandler)(GdbCmdContext *gdb_ctx, void *user_ctx); * '.' -> Skip 1 char unless reached "\0" * Any other value is treated as the delimiter value itself */ +#define GDB_CMD_PARSE_ENTRY_CMD_SIZE 20 +#define GDB_CMD_PARSE_ENTRY_SCHEMA_SIZE 8 typedef struct GdbCmdParseEntry { GdbCmdHandler handler; - const char *cmd; + const char cmd[GDB_CMD_PARSE_ENTRY_CMD_SIZE]; bool cmd_startswith; - const char *schema; + const char schema[GDB_CMD_PARSE_ENTRY_SCHEMA_SIZE]; } GdbCmdParseEntry; static inline int startswith(const char *string, const char *pattern) @@ -1481,14 +1483,14 @@ static int process_string_cmd(void *user_ctx, const char *data, for (i = 0; i < num_cmds; i++) { const GdbCmdParseEntry *cmd = &cmds[i]; - g_assert(cmd->handler && cmd->cmd); + g_assert(cmd->handler && *cmd->cmd); if ((cmd->cmd_startswith && !startswith(data, cmd->cmd)) || (!cmd->cmd_startswith && strcmp(cmd->cmd, data))) { continue; } - if (cmd->schema) { + if (*cmd->schema) { schema_len = strlen(cmd->schema); if (schema_len % 2) { return -2;