From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id D94771F45E for ; Wed, 19 Feb 2020 10:44:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726762AbgBSKo6 (ORCPT ); Wed, 19 Feb 2020 05:44:58 -0500 Received: from pb-smtp20.pobox.com ([173.228.157.52]:50288 "EHLO pb-smtp20.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726469AbgBSKo5 (ORCPT ); Wed, 19 Feb 2020 05:44:57 -0500 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id D2641BE12F; Wed, 19 Feb 2020 05:44:55 -0500 (EST) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=kDity66cyUdw4Ue/u8XBVy4GNQw=; b=KIgVCR sz7UaxNxXjyT9Phyy81f83igC4rsJuthNAtDToycxrJw09FRWwDPbQSuQ5iNQI5Q KecadTyKqymRpHM0XDafUaXBbXWvuX4OVIS180vKvPnWKHmnx1F38lO2FRCA2D1+ 44JN5W+0MwF8UWhBJk4Sv8ETrWf1OggufGPPo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=gprfcCwRcS4dTTICWTXUj2MuCuU14m9q BGbNjSXh65P7c+/Kka9K7JaQhfKZ9VQUzj2K2WJttwj6HbMNYE9QMGt+C6lCDbQY 1LMzGPellvrWFj2yJjFsQcI9oe5v3zCgzUlpb0diHbt4yyqS7s/50oBuORjDcbls MU50Zbydtm8= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id CC136BE12E; Wed, 19 Feb 2020 05:44:55 -0500 (EST) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [34.76.80.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 06EE8BE12D; Wed, 19 Feb 2020 05:44:52 -0500 (EST) (envelope-from junio@pobox.com) From: Junio C Hamano To: Robear Selwans Cc: Abhishek Kumar , git@vger.kernel.org, =?utf-8?Q?Ren=C3=A9?= Scharfe , =?utf-8?B?Tmd1eeG7hW4g?= =?utf-8?B?VGjDoWkgTmfhu41j?= Duy , Jeff King , Pratik Karki Subject: Re: [GSoC][RFC][PATCH 2/2] STRBUF_INIT_CONST: Adapting strbuf_* functions References: Date: Wed, 19 Feb 2020 02:44:50 -0800 In-Reply-To: (Robear Selwans's message of "Wed, 19 Feb 2020 06:34:19 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: DC5F8A96-5304-11EA-8737-B0405B776F7B-77302942!pb-smtp20.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Robear Selwans writes: > On Wed, Feb 19, 2020 at 5:13 AM Junio C Hamano wrote: >> >> Yes, but the case that matters to _your_ use is sb->alloc == 0. You >> do not want to let a broken strbuf (presumably broken by changes >> other than your own) to pass, when you can detect it. And for that, >> paying attention to sb->len _might_ make sense, but then the check >> won't be >> >> if (sb->alloc < sb->len) >> make it mutable; >> >> you'd rather be writing something like >> >> if (!sb->alloc) >> make it mutable; >> else if (sb->alloc < sb->len) >> BUG("somebody fed a corrupt strbuf to me"); > > Ooh so what you meant, is that corrupt `strbuf`s need to be > anticipated even if they > don't make much sense. Smart. I don't know if that is smart, but the point is that sb->alloc is the only thing you need to care about if you want to see if the strbuf is borrowing from a const string, and it does not make much sense not to catch a corruption, _if_ you are to check the value of sb->len as well.