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 DF3A53858D32 for ; Sat, 5 Nov 2022 01:54:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DF3A53858D32 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=1667613298; 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=QvtZF2g69HYuRWEy6W0SLcsUDBD7mYgNCA4oozfny3w=; b=Ns62SRk4R7voTP7DfcXImDtrEM+ZN+ZqX5RBRsXQZc124T7NydlS1uPjjptBT+XdYQ+hU/ SrM2Fw9K/ckIkbZ2GUzZKDN36EqlKYVPevQtY2bA6HOc8OLjhY7HtDE4zlax7Npm4v3VGb ljDGE9MhcMJQNVGUqjgO2vt8jjbQUO4= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-510-w_fpjWfYOaKyA1l_Fa2Mfw-1; Fri, 04 Nov 2022 21:54:57 -0400 X-MC-Unique: w_fpjWfYOaKyA1l_Fa2Mfw-1 Received: by mail-qt1-f197.google.com with SMTP id ff5-20020a05622a4d8500b003a526107477so4835893qtb.9 for ; Fri, 04 Nov 2022 18:54:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Vno7TKG3qnl7C0HzqCTTjKNeeuohRJPKh3FgETKcA0E=; b=YPHgCyTwgHc8KiR5ARG3kG4otY4b03AL7PNQEL/A9ZEfH5IgV7JQqpCX1+bJxiXGim rIKZwC8x71+plnrm3+3kB0X7OCSrwLKGhi10IZPhuOUs+F4Xf0Dj3xYaCkR2JqXLPp1i lnNoH2b19Khay6NgMfwx63p371xsqAbPm14lw2vthx1JsY4HVZOhtMalwynIc8HJgvqd B+IK3m677C3z8/eTY8t0yoKTaB6CAkSaeYZWrqYrSHnr7+ttT6KWtrsviNL72Frl1zNJ Ae0RVLqfBdM7Nnmy4huJuuN2UD6tABxT8bBjnQ+3N0lx83wlh8pyKaHPRkTcaHyco9Y1 jbHw== X-Gm-Message-State: ACrzQf1rE/YIHZiiZfjHBnmW3hvBYUqYo9MaGwRhdIjlzwWWxvAciNIi oKh1/HDv8eGIizIgIqfg9649HzRBWz48FYZu5R8hV7Fn1cCCiYQNZ+Wm0ZVRXLFmUd1mUzkPdjs yZ6ZiHyeGLT0vmuA7tQ== X-Received: by 2002:a0c:e18f:0:b0:4bb:5b84:fb2c with SMTP id p15-20020a0ce18f000000b004bb5b84fb2cmr35247108qvl.28.1667613296731; Fri, 04 Nov 2022 18:54:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5IVNZsyXyKumVPKVRs7yspTqwmO8i/h7UgEVWozZ70yq9+bquHWrx1PF+s7dhQ62Grqg94SQ== X-Received: by 2002:a0c:e18f:0:b0:4bb:5b84:fb2c with SMTP id p15-20020a0ce18f000000b004bb5b84fb2cmr35247099qvl.28.1667613296488; Fri, 04 Nov 2022 18:54:56 -0700 (PDT) Received: from t14s.localdomain (c-73-69-212-193.hsd1.nh.comcast.net. [73.69.212.193]) by smtp.gmail.com with ESMTPSA id x20-20020a05620a449400b006faaf6dc55asm164785qkp.22.2022.11.04.18.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 18:54:56 -0700 (PDT) Message-ID: <6869af802df401a086e4da6397410906b9765c62.camel@redhat.com> Subject: Re: [PATCH 5b/6] diagnostics: Remove null-termination requirement for json::string From: David Malcolm To: Lewis Hyatt Cc: gcc-patches@gcc.gnu.org Date: Fri, 04 Nov 2022 21:54:55 -0400 In-Reply-To: <20221104210550.GA92497@ldh-imac.local> References: <20221104210550.GA92497@ldh-imac.local> User-Agent: Evolution 3.44.4 (3.44.4-1.fc36) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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: On Fri, 2022-11-04 at 17:05 -0400, Lewis Hyatt wrote: > [PATCH 5b/6] diagnostics: Remove null-termination requirement for > json::string >=20 > json::string currently handles null-terminated data and so can't work > with > data that may contain embedded null bytes or that is not null- > terminated. > Supporting such data will make json::string more robust in some > contexts, such > as SARIF output, which uses it to output user source code that may > contain > embedded null bytes. >=20 > gcc/ChangeLog: >=20 > =09* json.h (class string): Add M_LEN member to store the > length of > =09the data.=C2=A0 Add constructor taking an explicit length. > =09* json.cc (string::string):=C2=A0 Implement the new constructor. > =09(string::print): Support print strings that are not null- > terminated. > =09Escape embdedded null bytes on output. > =09(test_writing_strings): Test the new null-byte-related > features of > =09json::string. >=20 [...snip...] > diff --git a/gcc/json.h b/gcc/json.h > index f272981259b..f7afd843dc5 100644 > --- a/gcc/json.h > +++ b/gcc/json.h > @@ -156,16 +156,19 @@ class integer_number : public value > =C2=A0class string : public value > =C2=A0{ > =C2=A0 public: > -=C2=A0 string (const char *utf8); > +=C2=A0 explicit string (const char *utf8); > +=C2=A0 string (const char *utf8, size_t len); > =C2=A0=C2=A0 ~string () { free (m_utf8); } > =C2=A0 > =C2=A0=C2=A0 enum kind get_kind () const final override { return JSON_STR= ING; } > =C2=A0=C2=A0 void print (pretty_printer *pp) const final override; > =C2=A0 > =C2=A0=C2=A0 const char *get_string () const { return m_utf8; } I worried that json::string::get_string previously returned a NUL- terminated string, but now there's no guarantee of termination, and that this might break something. But I checked, and it seems that this accessor doesn't get used anywhere in our source tree. > +=C2=A0 size_t get_length () const { return m_len; } Does anything actually use this? Perhaps it might make sense to delete the get_string accessor, and if we ever need one, replace it with an accessor that returns a char_span? > =C2=A0 > =C2=A0 private: > =C2=A0=C2=A0 char *m_utf8; > +=C2=A0 size_t m_len; > =C2=A0}; > =C2=A0 Thanks for adding the unit test. The 5b patch is OK for trunk. Dave