Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wIqvI-008XIp-0p for pgsql-hackers@arkaria.postgresql.org; Fri, 01 May 2026 16:41:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wIqvG-00Ba1X-02 for pgsql-hackers@arkaria.postgresql.org; Fri, 01 May 2026 16:41:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wIqvF-00Ba1O-0a for pgsql-hackers@lists.postgresql.org; Fri, 01 May 2026 16:41:01 +0000 Received: from fout-a6-smtp.messagingengine.com ([103.168.172.149]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wIqvB-00000004IOL-42uA for pgsql-hackers@postgresql.org; Fri, 01 May 2026 16:41:00 +0000 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id 52393EC0141; Fri, 1 May 2026 12:40:55 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Fri, 01 May 2026 12:40:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1777653655; x=1777740055; bh=C1dF/lcp7M wHF/fR216etBI0j5NA9Zc9lKGmfTdnMLg=; b=F1ERSi6P9Em66XgSpyn5Jb4RtF jDinN+BCO9UW6R4v959YouOn6ODxuk58hxQjr9iui0seSAo3pHRdTzjtjG5hmPFo PkwzUm7wK8kbmTgdYTEWUpnm5YoiMhN6nqlUH4aIYL/fGDnbXqhN9+Fn50cKeAmm mymkeRJvFAknd17HRUOtkZOS6EtmS3I1frj1vfO3zNFmtqd8f/pzrQys0Fq8gJPu c0eIrfBuv+URUDG6maY66fJbCGBmpT7GagSJRrLfWPhkLcNvPdz/NPUR7PPDe15n 808QeUCdOOaVU/23/Fb0te0mVDH2lt3YrTmAYtRrCVBSJH0PjWDtpg0PwOQQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1777653655; x=1777740055; bh=C1dF/lcp7MwHF/fR216etBI0j5NA9Zc9lKG mfTdnMLg=; b=TSLpiAgaQ+E8ScxsNMc1odmmX75uMdA1GCx9tReE4bARLqPSN2g H4tdH+9I0ZXBh4yxsgeYApjT7gjBodErm1rnO9kRcCHjrqRwFk1e1mRIGbOoqPzW LlH89NXNq+j83XlD220m5wxhTTtiaCxRXB+5S1Fo8rrzTQvdJuxKJgcSm7dOroHe LRtbKe9Vptwy8vQQuEq5z8KFQRdp8T5Z5ebZNbwP/m4KsQRYzpa+IuShGHC0VQSY FqTUrkFs3dI6S+tJbbMoGmd2uDDh9UhA2ytl0q6/44pHKJ5jRt6BNhiQpgKOmDca LogrYTR0ATF13Lrmp3DvgUfPBlsTNVsfXdw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdeltdejtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepfffhvfevuffkfhggtggujgesthdtsfdttd dtvdenucfhrhhomheptehnughrvghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghr rgiivghlrdguvgeqnecuggftrfgrthhtvghrnhepfeffgfelvdffgedtveelgfdtgefghf dvkefggeetieevjeekteduleevjefhueegnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomheprghnughrvghssegrnhgrrhgriigvlhdruggvpdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehpghhsqhhl sehjqdgurghvihhsrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrshesph hoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 May 2026 12:40:54 -0400 (EDT) Date: Fri, 1 May 2026 12:40:54 -0400 From: Andres Freund To: Jeff Davis Cc: pgsql-hackers@postgresql.org Subject: Re: Refactor: allow pg_strncoll(), etc., to accept -1 length for NUL-terminated cstrings. Message-ID: References: <2d758e07dff26bcc7cbe2aec57431329bfe3679a.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2d758e07dff26bcc7cbe2aec57431329bfe3679a.camel@j-davis.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2024-08-22 11:00:54 -0700, Jeff Davis wrote: > Like ICU, allow -1 length to mean that the input string is NUL- > terminated for pg_strncoll(), pg_strnxfrm(), and pg_strnxfrm_prefix(). > > This simplifies the API and code a bit. I don't really like this. I was hacking on a patch that uses compiler annotations to tell the compiler what range of memory a function access. The compiler then can use that knowledge to give you both compile-time warnings and, more importantly, it makes ubsan much more accurate. It'll e.g. often be able to warn you if a function accesses more memory than its annotation would suggest, even if the memory is part of a larger memory allocation (something asan, valgrind etc can't warn about, yet are often the most security critical issues). I found a bunch of issues that way already. But the annotations can't work if the access size is sometimes is -1. I also don't find this very convincing code-wise. You end up with lots of branches for -1. You have to support cases where one of the arguments is specifies as -1 and the other one with a real length, even though that's presumably a non-existing case. It seems reasonable to want the more efficient path for zero terminated strings with libc, but it seems like if we want that, we should add add a collate_method->strcoll, rather than have a strncoll that's not actually strncoll but strcoll. Greetings, Andres Freund