Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ilSbt-0004iU-7J for pgsql-hackers@arkaria.postgresql.org; Sun, 29 Dec 2019 07:03:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ilSas-00019L-IS for pgsql-hackers@arkaria.postgresql.org; Sun, 29 Dec 2019 07:02:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ilSar-00019D-T1 for pgsql-hackers@lists.postgresql.org; Sun, 29 Dec 2019 07:02:30 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ilSan-0004NN-Rw for pgsql-hackers@postgresql.org; Sun, 29 Dec 2019 07:02:27 +0000 Received: by mail-pg1-x542.google.com with SMTP id x7so16572958pgl.11 for ; Sat, 28 Dec 2019 23:02:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=TXNmdrCh+2GWHXh91g0C07RH5GBpEgVsoa3hdjgGsDE=; b=NuD7VaZa9qgR6b/kNQ9sa3DwdzViTbH65OZG9ZShq+hjtAa1VuYau+IWe2nAI9yorR ul1wNuJnNicwKMT0WzBdItWCRjxFoeg0v6sMqauZY1YYW9owhNu380ocDxifNJ0WwZWk YhUQw2RmOiOX0yA1ZaEOvczy7qFmzWFory0fk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=TXNmdrCh+2GWHXh91g0C07RH5GBpEgVsoa3hdjgGsDE=; b=iGUteRXnF6y/7Am/+KZ4KhApNoRKcvsAV+P3OOWitUftLVOd5GF1GW3JZ7BhloR7VY BhXD+Yd4YtdG5SAg61tyYqWO/MX3BSfkGB1kvyo0n1rnBXNwvdMB4RjFGMk8GBCz22Ql dr+EEZeljhJnacORV7pYFPOFbFqXf76ISAcddwomMentQk0NTsfjZVswmsnZkgz0JcMI uRnU052LpwQ296ioHteqpOP2MmP+/sJGjJaA1EoJOc+gIT4jJjBRc7DXXXmdYvxkJFHE YFy63jI6zvx8fooiy8S05VKv2DMZ/809RXAOvovdQG4g4lwA/S8tF+fbooOEo7eedPjN ZaOw== X-Gm-Message-State: APjAAAWErEdY2E+r0GVUcEf25O4lwa8pETRrCDt2FwdIAmz+D4Ot9TVm 2DZWjixOVNSVS/9IT0dRqMidxQ== X-Google-Smtp-Source: APXvYqwb7XGwxV+PCCMAThAcCR1rq+tYnOpFm0awx9HitC01Vx2jd0wLjmcnZYKa9ErFXjR1e98Mfg== X-Received: by 2002:a63:5b0a:: with SMTP id p10mr63843776pgb.228.1577602943939; Sat, 28 Dec 2019 23:02:23 -0800 (PST) Received: from gust.leadboat.com (64-118-100-82.static.sti.net. [64.118.100.82]) by smtp.gmail.com with ESMTPSA id g24sm46094693pfk.92.2019.12.28.23.02.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Dec 2019 23:02:23 -0800 (PST) Date: Sun, 29 Dec 2019 02:02:21 -0500 From: Noah Misch To: Thomas Munro Cc: Tom Lane , Pg Hackers Subject: Re: Consolidate 'unique array values' logic into a reusable function? Message-ID: <20191229070221.GA13873@gust.leadboat.com> References: <22244.1470585142@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="AhhlLboLdkugWU4S" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --AhhlLboLdkugWU4S Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Nov 04, 2019 at 12:02:21PM +1300, Thomas Munro wrote: > Rebased. I'm planning to commit this soon. In each installcheck-parallel run under valgrind-3.14.0, I now see ~1200 reports like this: ==00:00:00:28.322 1527557== Source and destination overlap in memcpy(0x1000104, 0x1000104, 4) ==00:00:00:28.322 1527557== at 0x4C2E74D: memcpy@@GLIBC_2.14 (vg_replace_strmem.c:1035) ==00:00:00:28.322 1527557== by 0xA9A57B: qunique (qunique.h:34) ==00:00:00:28.322 1527557== by 0xA9A843: InitCatalogCache (syscache.c:1056) ==00:00:00:28.322 1527557== by 0xAB6B18: InitPostgres (postinit.c:682) ==00:00:00:28.322 1527557== by 0x91F98E: PostgresMain (postgres.c:3909) ==00:00:00:28.322 1527557== by 0x872DE9: BackendRun (postmaster.c:4498) ==00:00:00:28.322 1527557== by 0x8725B3: BackendStartup (postmaster.c:4189) ==00:00:00:28.322 1527557== by 0x86E7F4: ServerLoop (postmaster.c:1727) ==00:00:00:28.322 1527557== by 0x86E0AA: PostmasterMain (postmaster.c:1400) ==00:00:00:28.322 1527557== by 0x77CB56: main (main.c:210) ==00:00:00:28.322 1527557== { Memcheck:Overlap fun:memcpy@@GLIBC_2.14 fun:qunique fun:InitCatalogCache fun:InitPostgres fun:PostgresMain fun:BackendRun fun:BackendStartup fun:ServerLoop fun:PostmasterMain fun:main } This is like the problem fixed in 9a9473f; the precedent from there would be to test src!=dst before calling mempcy(), e.g. as attached. I suppose the alternative would be to add a suppression like the one 9a9473f removed. I do wonder why the Valgrind buildfarm animals haven't noticed. --AhhlLboLdkugWU4S Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="qunique-valgrind-v1.patch" diff --git a/src/include/lib/qunique.h b/src/include/lib/qunique.h index 4d620f8..fc539ca 100644 --- a/src/include/lib/qunique.h +++ b/src/include/lib/qunique.h @@ -30,8 +30,9 @@ qunique(void *array, size_t elements, size_t width, for (i = 1, j = 0; i < elements; ++i) { - if (compare(bytes + i * width, bytes + j * width) != 0) - memcpy(bytes + ++j * width, bytes + i * width, width); + if (compare(bytes + i * width, bytes + j * width) != 0 && + ++j != i) + memcpy(bytes + j * width, bytes + i * width, width); } return j + 1; @@ -55,8 +56,9 @@ qunique_arg(void *array, size_t elements, size_t width, for (i = 1, j = 0; i < elements; ++i) { - if (compare(bytes + i * width, bytes + j * width, arg) != 0) - memcpy(bytes + ++j * width, bytes + i * width, width); + if (compare(bytes + i * width, bytes + j * width, arg) != 0 && + ++j != i) + memcpy(bytes + j * width, bytes + i * width, width); } return j + 1; --AhhlLboLdkugWU4S--