From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 21256 invoked from network); 26 Oct 2023 09:20:06 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 26 Oct 2023 09:20:06 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1698312006; b=RfJWTaDMXdYtwhv1EeFAA9CYsHiYLzfgnlJY+sP2yT6lGA8I4GF/utzgLs4/jNTu29t7jc5QMR 2H04D7EZuJA3FnjzDPfE6L8on4EQFJ8pqz4WS50Xd5DzFiqD5c6FgGMUdsO45xkdaTa/Y8CGvJ LozVfBoak8Sgt8OLAiIDVNtvkLhz9eyxVB4M+SYAazpb/xNrxpSh7XZLQ1ho66w+K1RraiAqlt /A0JNKESa3MbYI4R8lFV4mDQGqt7qv6SmPkBBWOMIzBoXCIGqwdgUfV5JLgqC7LZG7tjT2c+0/ C+tThvQLB8A+tLunOYDymhl9wPPBZ/kdaasTEkMHLNMuIA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f178.google.com) smtp.remote-ip=209.85.208.178; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1698312006; bh=z7TEkUsNaEkGPUIcnNC9oht3Ku2DXL+OTfibmrKqKUk=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=Z8aKY7X2Wrr5ZSrSmY2EhAyhau+PY7wdTfFLxfNM7i7qoH50kB5xfjcCpNBxeRkFmKkw3BFvkA 1rQT0cdLasR1ty6dlpgA0IyL3Vqz5+kz3PVofQjKOMdyNkafPs7DhflHQFcmvrhAbQPsIeLBIl d9bfhPmB+y2cqwGVsos/g/cjy93LGPUYpR5LO59DkFv38p3Qqy7qz/rCeE4l18fQdJzSLkpRc1 O7Rg7pHyij2Nf9BvjSYkz+7tWlRbt483qDb2hT7qIHPuWiIIEYTcsnd73vZEyPb1C6k5+dF0dG WN+R+lMMZN7NQUf5V+Az7KqbnyAYUBw8LoV3Us/5jJfQ6g==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=PZWOwowpcSzGNRCdtSkAyGBSAbQzhOQ0iIdEhc8iaAU=; b=YFRwv++FOMxuJa/45/xP4hhvEC S+z0NbDwweXSvO5TJe4ySTd6fsL5THhkeuQ3YaECD0J/gQO+eaVqCgpTRbPylAbtwv/55ynGuxR4m CHCj3hPOU29gg4Z+tvGNHyB++r8dGTJiFz0TIYIoYEJAp+xzflKB9mqVbAzvTxkPknyJYrxKbaHA/ /8gPAAc033f2898mZEq96ZBfaxGni8WfGoOKvaZ6cN7LyoDMBJGEj4Two9m6ja9YtFJ3GHFCxqkMH ctkmpUAj92X5SOcEu7HKJFk05ZcgcpNuloF51n8JZFCeBNyHJOOSkw8nRDbS0Ruxqq30pc6zJyybt Yw4ZyWag==; Received: by zero.zsh.org with local id 1qvwX7-000Knn-JP; Thu, 26 Oct 2023 09:20:05 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f178.google.com) smtp.remote-ip=209.85.208.178; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lj1-f178.google.com ([209.85.208.178]:42467) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1qvwWV-000KUe-Ap; Thu, 26 Oct 2023 09:19:28 +0000 Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2c1807f3400so7324341fa.1 for ; Thu, 26 Oct 2023 02:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698311966; x=1698916766; darn=zsh.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=PZWOwowpcSzGNRCdtSkAyGBSAbQzhOQ0iIdEhc8iaAU=; b=XcGTSiJuWxaRgHO8PO64lcxt5dKINcEzr0GglS8vJUYSoXkEhrDoOoavRsV2zP7XaD eROpJ9+gJSpRDsSuXP1L/HdbqWEfnPjJ9teFx0l4BKB32QmEbP1aHUDCnKDlxwn4bIou vz89Z4jL1do51o+a40lt5cWaZ5jQ3YzGEMDy1dcozo1NfeDqXakvfioKfWy/dDR8M+a+ 1b2E6y92keTIXxJq6jBlz9APZgOBTBntcbb3Q1dVbAB5OXvttY2hAWEo66aUAypnXDHI iSktevm5dPBd4+TX6+/bgiUT1kJX5ERJTbBydLtQcZFYi7REQu9hWyNC4mbK0P8PHvwV 2pmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698311966; x=1698916766; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PZWOwowpcSzGNRCdtSkAyGBSAbQzhOQ0iIdEhc8iaAU=; b=qjlRYK+R3J6cwg+q45JM3jxKzz44ibbTHCLd2e8RXwJm1H9XKmeaABkNitQ1SbH2dg YyQNWLqcDJ3S86U8VINhdKKNr8r3DBKklmawLzP7f9hfpf2W6IcSs3vXwVOh4Ti9CsM4 mQyl4I/1qOK8Sn3R4IZuLEZCSxIjmWlVkBJDBC3z8le0OxJL4ldh9/eNlowD+J8K+CMq 8j/AUo/t+8V+C16pm+Y7rlABLD2GIGlbktGGZn+yIR5GW9eFg29W8E8AF/ouRt6DgAc8 9bVJFx6PJgNeu82bUKfWPSZe7afSajXE3OyAnkHEK3Xqe6w64DxtIFAUsWuLckFg3wwe Zw4w== X-Gm-Message-State: AOJu0YwNl74Vp9qIzo4DOSDrU/2XjT/aq4oAWKo3eQqVMy322aZQDN2W Wud/RXoqkPwu3XVv01tM53MrDUqnp0mGPwu+xD3rri8BVz/8rQ== X-Google-Smtp-Source: AGHT+IGJvCbyFpoFaczod1GdoJO3rk1/ixAevGfexImx88YpRAz7gGaHHeLiLsY7yLpTe6pziTEr/SvSzuFbevX4AXA= X-Received: by 2002:a05:651c:1a0e:b0:2c5:4312:3425 with SMTP id by14-20020a05651c1a0e00b002c543123425mr870855ljb.6.1698311966198; Thu, 26 Oct 2023 02:19:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Roman Perepelitsa Date: Thu, 26 Oct 2023 11:19:14 +0200 Message-ID: Subject: Re: [PATCH] Fix a bunch of Coverity-reported defects To: Bart Schaefer Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52248 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Thu, Oct 26, 2023 at 5:37=E2=80=AFAM Bart Schaefer wrote: > > A batch of the warnings that I ignored were assignments of one field > of a union to another field of the same union, e.g., a casted long > onto a double, etc., which elicited "overlapping copy" warnings. I'm > fairly confident we'd have seen things crashing by now if this wasn't > safe, but I mention it in case someone knows why it might be a > problem. This can indeed cause problems. The conditions under which it happens are subtle. Here's an example: https://godbolt.org/z/EvxTzM1hn. inline int foo(int* x, float* y) { *x =3D 1; *y =3D 2; return *x; } // Returns either 1 or 0x40000000 depending on the // absence or presence of -fno-strict-aliasing. int bar() { union { int x; float y; } z; return foo(&z.x, &z.y); } // The same as bar() but with the call to foo() // manually inlined. Return 0x40000000 with and // without -fno-strict-aliasing. int baz() { union { int x; float y; } z; // The following code is equivalent to // return foo(&z.x, &z.y). int* x =3D &z.x; float* y =3D &z.y; *x =3D 1; *y =3D 2; return *x; } When compiled with `gcc -std=3Dc99 -O2`: bar: mov eax, 1 ret baz: mov eax, 0x40000000 ret When compiled with `gcc -std=3Dc99 -O2 -fno-strict-aliasing`: bar: mov eax, 0x40000000 ret baz: mov eax, 0x40000000 ret A simple workaround is to compile with -fno-strict-aliasing. This can result in slower code but I don't think it's likely to be noticable. Roman.