Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eoilC-0007ZH-PH for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Feb 2018 04:45:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eoilA-00030l-5k for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Feb 2018 04:45:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eoil9-00030b-V2 for pgsql-hackers@lists.postgresql.org; Thu, 22 Feb 2018 04:45:32 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eoil6-0006ZZ-94 for pgsql-hackers@postgresql.org; Thu, 22 Feb 2018 04:45:30 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w1M4jMh7021222; Wed, 21 Feb 2018 23:45:22 -0500 From: Tom Lane To: Mark Dilger cc: Andres Freund , Pg Hackers Subject: Re: [HACKERS] Constifying numeric.c's local vars In-reply-to: References: <20170910232154.asgml44ji2b7lv3d@alap3.anarazel.de> <11630.1505131814@sss.pgh.pa.us> <267E42E4-2C53-4791-AEDA-9FB959DB6C4D@gmail.com> Comments: In-reply-to Mark Dilger message dated "Wed, 21 Feb 2018 09:12:51 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <21220.1519274722.1@sss.pgh.pa.us> Date: Wed, 21 Feb 2018 23:45:22 -0500 Message-ID: <21221.1519274722@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Mark Dilger writes: >> This means that the const variable 'const_zero' contains a pointer that is >> non-const, pointing at something that is static const, stored in read only >> memory. Yikes. > I still believe this is unsafe. I'm with Andres: I don't see the problem. It's true that we've casted away a chance for the compiler to notice a problem, but that's not the only defense against problems. If we did try to modify const_zero, what should happen now is that we get a SIGSEGV from trying to scribble on read-only memory. But that's actually a step forward from before. Before, we'd have successfully modified the value of const_zero and thereby silently bollixed subsequent computations using it. Since, in fact, the code should never try to modify const_zero, the SIGSEGV should never happen. So effectively we have a hardware-enforced Assert that we don't modify it, and that seems good. As far as compiler-detectable mistakes go, Andres' changes to declare various function inputs as const seem like a pretty considerable improvement too, even if they aren't offering 100% coverage. regards, tom lane