From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 765FF3858D33 for ; Wed, 12 Apr 2023 20:47:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 765FF3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681332477; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=w6NKaRvEUq5zNftiFj4F4prV/XA60bT36E4j0VykbXY=; b=hqfAeMVSGBcOgRMa/rwn/oVzC6AfHct5bm/G5nDJu8HC9yt+3cIwJKr2eOixRr64Hkep2Y karRJiE92MBz+skp0rbbjJxw+un8lA6kvRk/zq7unuAiCwWBq2bdPXsOPnWynjizNcP3Tc uJyxx6YEWqPQb6Osw/IKEuNjIN40cbA= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-418-YO7pJ57nOl6jXzqVrjARjA-1; Wed, 12 Apr 2023 16:47:55 -0400 X-MC-Unique: YO7pJ57nOl6jXzqVrjARjA-1 Received: by mail-ed1-f70.google.com with SMTP id x5-20020a50d605000000b005066c2aa22aso295410edi.17 for ; Wed, 12 Apr 2023 13:47:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681332474; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=w6NKaRvEUq5zNftiFj4F4prV/XA60bT36E4j0VykbXY=; b=X/pB2+H5utekNmRW0n/c3QiMg4Fom6uYfxtbuIa3q2ysRBhQAqxPW4Hb3gYJQahFyh j3xtJ7wa/BegCcdaFrMbLIJdoYcJdQsFxSCqR6GCmTN72l8j2EU5TkGh6Xb8pyL/aHKF 1AUGG+ynIe9OkbBElEvlEAn6U85qYHHxKucBOJH1D7V5O30xD5Jusr0yMMPag6JAqkOK HNUTeWWQGsToQl9KBHS0HG7qkI0oOPKicwl7Xh6r1+iOxCDdHM2ydImYetlYi46wxoIK 5xiIOO7BGX1u5u5pOLLLWz6f8EUSAQsK8/+gCjnkZCBrPLZiN62RuAKIoMY40bna5brm /RCw== X-Gm-Message-State: AAQBX9espvpu78HX8PPQEI9LRVNnFPGEKTXA2y0sTYMPvMdhs8fjvH4r rNb3aUHo69k8zJXj04Q5SUDqRXRGAAec26KF2HmF52bQ4h1pBDoQXQNN41oywZExAlb2Cycqg24 wPE8RjE6ZMr0I/2/7NQYwiaMAJSz7MA== X-Received: by 2002:a17:906:c7c3:b0:94a:9ec7:108c with SMTP id dc3-20020a170906c7c300b0094a9ec7108cmr205046ejb.27.1681332474607; Wed, 12 Apr 2023 13:47:54 -0700 (PDT) X-Google-Smtp-Source: AKy350YwvK/t1xInYjpnPkEUDWatne5PXGs1tAfP15FwlX3ux5+rvFITsPrsCreonljdssQGxLNM3g== X-Received: by 2002:a17:906:c7c3:b0:94a:9ec7:108c with SMTP id dc3-20020a170906c7c300b0094a9ec7108cmr205037ejb.27.1681332474318; Wed, 12 Apr 2023 13:47:54 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id 24-20020a170906319800b008e9c79ff14csm7613324ejy.96.2023.04.12.13.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 13:47:53 -0700 (PDT) From: Andrew Burgess To: Pedro Alves , Simon Marchi , gdb-patches@sourceware.org Subject: Re: [PATCH] gdb: fix missing null-character when using value_cstring In-Reply-To: <56b5d8f3-463e-7a73-3cf6-4da661172d4f@palves.net> References: <3d7197c2-424c-1458-93aa-d23fedac3d70@simark.ca> <87r0sxb0zy.fsf@redhat.com> <56b5d8f3-463e-7a73-3cf6-4da661172d4f@palves.net> Date: Wed, 12 Apr 2023 21:47:52 +0100 Message-ID: <87o7nsakuf.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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: Pedro Alves writes: > On 2023-04-06 2:20 p.m., Andrew Burgess via Gdb-patches wrote: >> Simon Marchi writes: >> >>> On 4/3/23 17:49, Andrew Burgess via Gdb-patches wrote: > >>>> Alternatively, if we change the requirements of value_cstring so that >>>> we require the passed length includes the trailing null, then we can >>>> assert that this is indeed the case within value_cstring. Any >>>> incorrect uses in the future will be quickly spotted. >>>> >>>> So that's what I did, c_string_operation::evaluate is left unchanged, >>>> but every other use of value_cstring is adjusted with a '+ 1' so that >>>> we include the null within the length being passed. >>> >>> That sounds counterintuitive to me. With an API of style pointer + >>> length, I don't expect the length to include the null terminator. It >>> also unnecessarily forces the caller to have a null-terminated version >>> of the string, which may not always be the case (you might want to call >>> value_cstring on a subset of an existing string). >>> >>> I think that: >>> >>> struct value * >>> value_cstring (const char *ptr, ssize_t len, struct type *char_type) >>> >>> should take a length excluding the null terminator, but a null >>> terminator in the result (its job is to build a C string, and a C string >>> requires a null terminator at the end). >> >> This is why writing comments is so important :) >> >> I read it as "build a value* from this C-string", which is why I figured >> we can assume there will be a '\0' at the end. >> >> Anyway, I don't really mind either way, just so long as we can get >> something that works! I'll flip this around to the way you suggest and >> repost. >> > > Hmm, this rang a bell. See this patch and following discussion: > > https://inbox.sourceware.org/gdb-patches/20210713153142.3957666-1-simon.marchi@efficios.com/ > Thanks for pointing that out. I guess from the age of that patch it's not something you're planning to get back to anytime soon. I assume you'd have no objections if I rebased your patch and merged it with my tests and reposted it? Thanks, Andrew