From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 655143858C74 for ; Fri, 22 Dec 2023 03:35:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 655143858C74 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 655143858C74 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703216103; cv=none; b=Jk18g7UDALTa8ziGhuIMCg199FJSdJ1qd0mH5870aP5nQG7Nmg4DFc0xFBlcdiGXPEULGBhiD3WyfQk3X3aIA4Z6OqiyjqkYjQoQJ5w5PfnCi0oNhiht61M/zaBL+7ykuaNVjC5ZLv7qqtpk8tX8FIrpPtnFfEsUbALXuelt+Hc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703216103; c=relaxed/simple; bh=m/vZyuM1FOXQqQKl95fk42OjaujsDx5KZ/YugoVmlUQ=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=SRvG3hWT+iQaUTq4vGJXk7ksMBXmyG+ZBMNpB5oJtUUAGYd8WA7B7J+8+61RRgbT2ALg6W36MdQLZQI8CoO5VGnW/pO+/A+8tQJ1LTiNPI45b4VgO/FgxPmEJ8fH60iD5trjELXognhfZ9xjTG1ArPT/VF/sp2aPu51MTo8nFHI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1703216102; bh=m/vZyuM1FOXQqQKl95fk42OjaujsDx5KZ/YugoVmlUQ=; h=Date:Subject:To:References:From:In-Reply-To:From; b=F31jFA6D/YZGlqFiHAW7zui4uD0ROWU6U8+xDAVqTTfwzHgZwbozOg3qlpUJN/SAK 2NwwcBTTGwIa0gomyRxLP8yH6u4GX4rTpe9HG0TdTUSkFfmTkn0lKsAv3AiyOF0RHk 3t18bf/Dq3YWfFieiS9DC6beQ+GJSVEF60LCwT7w= Received: from [10.0.0.11] (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 0D1CC1E091; Thu, 21 Dec 2023 22:35:02 -0500 (EST) Message-ID: <9f9e76ad-46be-4f53-8820-58e6474e6589@simark.ca> Date: Thu, 21 Dec 2023 22:35:01 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 19/26] gdbserver: fix the declared type of register_status in regcache Content-Language: en-US To: Tankut Baris Aktemur , gdb-patches@sourceware.org References: <0c082e1edb5933f2ac5a7aac06197f8957099628.1677582745.git.tankut.baris.aktemur@intel.com> From: Simon Marchi In-Reply-To: <0c082e1edb5933f2ac5a7aac06197f8957099628.1677582745.git.tankut.baris.aktemur@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023-02-28 06:28, Tankut Baris Aktemur via Gdb-patches wrote: > The register_status field of regcache is declared as `unsigned char *`. > This is incorrect, because `enum register_status` from > gdbsupport/common-regcache.h is based on signed char and > REG_UNAVAILABLE is defined as -1. Fix the declared type. > > The get/set methods already use the correct type, but we update cast > operations in two places. > --- > gdbserver/regcache.cc | 4 ++-- > gdbserver/regcache.h | 4 ++-- > 2 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc > index 0e21c1aa7d1..09ea58bdbd6 100644 > --- a/gdbserver/regcache.cc > +++ b/gdbserver/regcache.cc > @@ -147,7 +147,7 @@ regcache::initialize (const target_desc *tdesc, > = (unsigned char *) xcalloc (1, tdesc->registers_size); > this->registers_owned = true; > this->register_status > - = (unsigned char *) xmalloc (tdesc->reg_defs.size ()); > + = (enum register_status *) xmalloc (tdesc->reg_defs.size ()); The malloc'ed size assumes that a register_status value is 1 byte long. register_status is indeed 1 byte long, but since it's hidden behind another name, it's not obvious. You could perhaps switch to: this->register_status = XNEWVEC (enum register_status, tdesc->reg_defs.size ()); Or C++ify it: this->register_status = new enum register_status[tdesc->reg_defs.size ()]; But then you have to change the free to a delete[], or store it in an std::unique_ptr. Simon