Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bLX2h-000459-8w for pgadmin-hackers@arkaria.postgresql.org; Fri, 08 Jul 2016 14:46:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bLX2g-0005AX-O3 for pgadmin-hackers@arkaria.postgresql.org; Fri, 08 Jul 2016 14:46:10 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bLX2T-0004vU-Qm for pgadmin-hackers@postgresql.org; Fri, 08 Jul 2016 14:45:57 +0000 Received: from mail.gathman.org ([2001:470:5:c85::10]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bLX2Q-0000j3-Va for pgadmin-hackers@postgresql.org; Fri, 08 Jul 2016 14:45:56 +0000 Authentication-Results: mail.gathman.org; auth=pass (PLAIN sslbits=128) smtp.auth=stuart DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gathman.org; i=@gathman.org; q=dns/txt; s=default; t=1467989151; h=From : Subject : To : Message-ID : Date : MIME-Version : Content-Type : From : Subject : Date; bh=Kzs/GMwl5chmEaXkDLxGwVCOOejUaxjbmyrIDbcPJ9w=; b=UFoizFyDRZkT9k76J9QEEnKzO9Ztdpe6cZEBnjPMz49B1HDKwVBH/kJDDkgZDQJwFRq0j3 3ugmC49Cgvu0OZb/KbAIVnQPPE2yzPaPjXpMl6mJm1kI0b988jXFVhjkoFOm/YF2OhAiCBOr X7Qw6zSooKNmxufocI3rovGpmbpCY= Received: from elissa.gathman.org (nomaddigitalinc-1.border10.wdc002.pnap.net [64.94.31.206] (may be forged)) (authenticated bits=0) by mail.gathman.org (8.14.4/8.14.4) with ESMTP id u68EjnUi020822 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Fri, 8 Jul 2016 10:45:51 -0400 From: Stuart Gathman Subject: [pgadmin3][Patch] Null this in pgConn::GetStatus To: pgadmin-hackers@postgresql.org Organization: Gathman Systems Jabber-Id: stuart@gathman.org Message-ID: <342698cb-0974-6b40-dfdf-cc505601d9c9@gathman.org> Date: Fri, 8 Jul 2016 10:45:51 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------BE156EED518398F675680C82" X-Pg-Spam-Score: -3.3 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgadmin-hackers Precedence: bulk Sender: pgadmin-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------BE156EED518398F675680C82 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Saw the convention to tag for pgadmin3 and patch, so posting a 3rd time. Sorry - new to pgadmin. pgadmin3-1.22.1 When compiled with gcc6, the evil practice of "this == 0" fails horribly. The most obvious effect is crashing during startup. I've attached a simple patch. The Fedora bugzilla is here: https://bugzilla.redhat.com/show_bug.cgi?id=1335043 A detailed explanation of why this == 0 is evil: http://www.viva64.com/en/b/0226/ The patch moves the guts of pgConn::GetStatus() to a static function, where comparing the ptr arg to 0 is well defined, and makes the GetStatus() member function call the static function inline. It is still technically undefined when calling the GetStatus member function on a null ptr - but for now the compiler is not eliminating the test. It is also a step in right direction, which would be to use the static function at calling sites where the ptr could be null. --------------BE156EED518398F675680C82 Content-Type: text/x-patch; name="pgadmin3-nullthis.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pgadmin3-nullthis.patch" diff -up ./pgadmin/db/pgConn.cpp.nullthis ./pgadmin/db/pgConn.cpp --- ./pgadmin/db/pgConn.cpp.nullthis 2016-07-01 13:18:44.649386521 -0400 +++ ./pgadmin/db/pgConn.cpp 2016-07-01 13:25:40.815813995 -0400 @@ -1003,15 +1003,15 @@ bool pgConn::IsAlive() } -int pgConn::GetStatus() const +int pgConn::GetStatus(const pgConn *p) { - if (!this) + if (!p) return PGCONN_BAD; - if (conn) - ((pgConn *)this)->connStatus = PQstatus(conn); + if (p->conn) // FIXME: casting away const ! + ((pgConn *)p)->connStatus = PQstatus(p->conn); - return connStatus; + return p->connStatus; } diff -up ./pgadmin/include/db/pgConn.h.nullthis ./pgadmin/include/db/pgConn.h --- ./pgadmin/include/db/pgConn.h.nullthis 2016-07-01 13:18:56.643512630 -0400 +++ ./pgadmin/include/db/pgConn.h 2016-07-01 13:24:07.339776340 -0400 @@ -215,7 +215,11 @@ public: { return PQbackendPID(conn); } - int GetStatus() const; + static int GetStatus(const pgConn *); + int GetStatus() const + { + return GetStatus(this); + } int GetLastResultStatus() const { return lastResultStatus; --------------BE156EED518398F675680C82 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgadmin-hackers --------------BE156EED518398F675680C82--