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 1kEccP-0005Og-7Y for pgsql-hackers@arkaria.postgresql.org; Sat, 05 Sep 2020 18:08:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kEccL-0001w0-Vd for pgsql-hackers@arkaria.postgresql.org; Sat, 05 Sep 2020 18:08:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kEccL-0001vs-OP for pgsql-hackers@lists.postgresql.org; Sat, 05 Sep 2020 18:08:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kEccF-0001vB-CW for pgsql-hackers@lists.postgresql.org; Sat, 05 Sep 2020 18:08:49 +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 085I8eWh1221797 for ; Sat, 5 Sep 2020 14:08:40 -0400 From: Tom Lane To: pgsql-hackers@lists.postgresql.org Subject: Dubious code in pg_rewind's process_target_file() MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1221795.1599329320.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Sep 2020 14:08:40 -0400 Message-ID: <1221796.1599329320@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk scan-build complains that "exists =3D false" is a dead store, which it is: process_target_file(const char *path, file_type_t type, size_t oldsize, const char *link_target) { bool exists; ... if (lstat(localpath, &statbuf) < 0) { if (errno !=3D ENOENT) pg_fatal("could not stat file \"%s\": %s\n", localpath, strerror(errno)); exists =3D false; } ... exists =3D (bsearch(&key_ptr, map->array, map->narray, sizeof(file_ent= ry_t *), path_cmp) !=3D NULL); It looks to me like we could replace "exists =3D false" with "return", rather than uselessly constructing a FILE_ACTION_REMOVE entry for a file we've already proven is not there. This seems to have been copy-and-pasted from process_source_file, without much thought for the fact that the situations are quite different. regards, tom lane