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.94.2) (envelope-from ) id 1qeixX-007hZf-0Y for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Sep 2023 21:24:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qeixV-00CtOX-56 for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Sep 2023 21:24:08 +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.94.2) (envelope-from ) id 1qeixU-00CtOI-N0 for pgsql-hackers@lists.postgresql.org; Fri, 08 Sep 2023 21:24:08 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qeixQ-003xcg-Gr for pgsql-hackers@postgresql.org; Fri, 08 Sep 2023 21:24:07 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68a3cae6d94so2346676b3a.0 for ; Fri, 08 Sep 2023 14:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1694208242; x=1694813042; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=nUOFxGWPuNZN8gUDXmJW/6/hHEsvS+rM66u2oWqcbwc=; b=2dd+sIjXGsq/ej2Ejuf7+4hcQPXt6h0i3j4LQqb9SNPkkN5gtb2hHEKpXkUonPjWSa +tbkpmbOwJN8+JNcxVOybvdX8cC4SdZOx2ISIxhRwXRZylqfGcCukzw+RBNWDoXSxyEY H3R/+Y7NjsrSefxp0+CzcsZUApT5KFRydyqfqIjWTa+ZP/BRop4Dy9RcVxJSJD9oCXCT tK7nMBw+zqXkN2fToa3no145lYNMegGCXrL5C30FgH/SnW9fq6vQhcXfl6PfAubPTG/u Qkuhh1lwZg8yRrhiSrq17M72n1KTUEl43mdaPyQeHP+Ey9LbGqv4WUfqfVAOh7uiggYN Aedw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694208242; x=1694813042; 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=nUOFxGWPuNZN8gUDXmJW/6/hHEsvS+rM66u2oWqcbwc=; b=d0ohppcax16Yz2ldRARKRVbAnI0nysBp97l3kP5zoh+O3NT6AaOcnr9VBJkuqEF0g5 sBkIZDY36Q/D2qm8CrBd+DLnUh3LCSlsecM747WDstoRF5BD1gT81lRXqdyzagJaoA/D mUyi67lZUTTi/ER3FHHz0t35wi5N8lhVRssFX06nBbyyABhxbmqHBbs9CDNAfSSI5iVY CDcDrPdJ8KzZmHJqaQ6KG+NvDgf4h/Q3SS4I5qOdohXpgCqUTegy3iISFPcjCp+NgFL3 4yWKhDIQIStqlXNMIGupTsEOfRxjJz3hBK+O6o00eyrDiGAiyQtPE6xedrOIYE4AYvV8 TGXQ== X-Gm-Message-State: AOJu0YwXPT3PhPChhDe2TO/Sr4w772s3dSN2OrKHDRBvkbn217rsad4B G3K5RBJzEgzMSAYvcU0khDw4dw== X-Google-Smtp-Source: AGHT+IFoSSqGSQ2b3OS7TLTjdNs85uAkcLm3xJEdwZQt6qYIDqaUtq/tD/VndMRTNFJKqdtBX3spnA== X-Received: by 2002:a05:6a00:1acb:b0:68e:46af:cfd4 with SMTP id f11-20020a056a001acb00b0068e46afcfd4mr3887250pfv.21.1694208242093; Fri, 08 Sep 2023 14:24:02 -0700 (PDT) Received: from [172.24.1.133] ([12.126.244.130]) by smtp.gmail.com with ESMTPSA id fk25-20020a056a003a9900b0065438394fa4sm1735178pfb.90.2023.09.08.14.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 14:24:01 -0700 (PDT) Message-ID: <7073610042fcf97e1bea2ce08b7e0214b5e11094.camel@j-davis.com> Subject: Re: Avoid a possible null pointer (src/backend/utils/adt/pg_locale.c) From: Jeff Davis To: Michael Paquier , Ranier Vilela Cc: Robert Haas , Pg Hackers Date: Fri, 08 Sep 2023 14:24:00 -0700 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 2023-09-08 at 15:24 +0900, Michael Paquier wrote: > Looking closer, there is much more inconsistency in this file > depending on the routine called.=C2=A0 How about something like the v2 > attached instead to provide more context in the error message about > the function called?=C2=A0 Let's say, when the provider is known, we coul= d > use: > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 elog(ERROR, "unsupported collprovid= er (%s): %c", > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "pg_s= trncoll", locale->provider); +1, thank you. > And when the provider is not known, we could use: > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 elog(ERROR, "unsupported collprovid= er (%s)", "pg_myfunc"); It's not that the provider is "not known" -- if locale is NULL, then the provider is known to be COLLPROVIDER_LIBC. So perhaps we can instead do something like: char provider =3D locale ? locale->provider : COLLPROVIDER_LIBC; and then always follow the first error format? [ Aside: it might be nice to refactor so that we used a pointer to a special static struct rather than NULL, which would cut down on these kinds of special cases. I had considered doing that before and didn't get around to it. ] > @Jeff (added now in CC), the refactoring done in d87d548c seems to be > at the origin of this confusion, because, before this commit, we > never > generated this specific error for all these APIs where the locale is > undefined.=C2=A0 What is your take here? Agreed. Regards, Jeff Davis