Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m6ZcW-0003Pk-NU for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Jul 2021 14:24:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m6ZcV-0000aZ-Mq for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Jul 2021 14:24:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m6ZcV-0000aN-FP for pgsql-hackers@lists.postgresql.org; Thu, 22 Jul 2021 14:24:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m6ZcT-0004pF-5c for pgsql-hackers@lists.postgresql.org; Thu, 22 Jul 2021 14:24:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 16MEO541780311; Thu, 22 Jul 2021 10:24:05 -0400 From: Tom Lane To: Peter Eisentraut cc: Ranier Vilela , Laurenz Albe , PostgreSQL Hackers Subject: Re: printf %s with NULL pointer (was Re: BUG #17098: Assert failed on composing an error message when adding a type to an extension being dropped) In-reply-to: <768db26c-cf9a-6943-38b1-2d5ac8cc86f2@enterprisedb.com> References: <17098-b960f3616c861f83@postgresql.org> <2468663.1626017338@sss.pgh.pa.us> <2984422.1626110456@sss.pgh.pa.us> <3227956.1626186568@sss.pgh.pa.us> <3280448.1626200778@sss.pgh.pa.us> <06a9ff0f-d1e9-0340-2f3b-180cefe41c7a@enterprisedb.com> <3517180.1626280000@sss.pgh.pa.us> <768db26c-cf9a-6943-38b1-2d5ac8cc86f2@enterprisedb.com> Comments: In-reply-to Peter Eisentraut message dated "Thu, 22 Jul 2021 08:20:28 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <780309.1626963845.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Thu, 22 Jul 2021 10:24:05 -0400 Message-ID: <780310.1626963845@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Peter Eisentraut writes: > On 14.07.21 18:26, Tom Lane wrote: >> https://git.musl-libc.org/cgit/musl/tree/src/stdio/vfprintf.c#n593 >> case 's': >> a = arg.p ? arg.p : "(null)"; > Similar here: > https://github.com/ensc/dietlibc/blob/master/lib/__v_printf.c#L188 I also took a look at μClibc, as well as glibc itself, and learned some additional facts. glibc's behavior is not just 'print "(null)" instead'. It is 'print "(null)" if the field width allows at least six characters, otherwise print nothing'. μClibc is bug-compatible with this, but other implementations seem to generally just substitute "(null)" for the input string and run with that. I'm inclined to side with the latter camp. I'd rather see something like "(nu" than empty because the latter looks too much like it might be correct output; so I think glibc is expending extra code to produce a less-good result. > I think unless we get counterexamples, this is all good. Barring objections, I'll press ahead with changing snprintf.c to do this. regards, tom lane