From owner-dev-commits-src-all@freebsd.org Fri Aug 6 16:44:16 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id AB503659341; Fri, 6 Aug 2021 16:44:16 +0000 (UTC) (envelope-from rob.fx907@gmail.com) Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GhBC43x18z4rHZ; Fri, 6 Aug 2021 16:44:16 +0000 (UTC) (envelope-from rob.fx907@gmail.com) Received: by mail-oo1-xc34.google.com with SMTP id h7-20020a4ab4470000b0290263c143bcb2so2377172ooo.7; Fri, 06 Aug 2021 09:44:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=a1LpHOj0V8F38XedG2+nRaYu+IPrFzA/ki2CiRwtUN8=; b=OyMp6MJ4GMwCKtnpJ5cBlehbTPtYxpcfV8n8PlVu6yVzy8CxclOn5rDmADJNHZnoDu O9SLnKKeG8n7twANUNjMhTWBFM/s2xQaojDVcWjN/mbqByMQ+to/VpUhfHMcvLBj/Pys bZmNeM7ppfz38sLZcgT0lIeWwSdXYGutCmjEYNvVWDayzzXvxT/8f5eyoJ/Z47oR9HDG FjaNjL0bW/F/2iaYWarQJXmE6sTXPoC3tzqNEOhi2M9jPMqUyku9PQ//A5IztFKfChfl mQDyoM3gx0lZgM9Jaa3l+OLMVARwJZ+gZjgjNrX/hIbJKMvKDHWx55G/19goUfvVPBEa 2kpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=a1LpHOj0V8F38XedG2+nRaYu+IPrFzA/ki2CiRwtUN8=; b=CGCo5HeeD4jE7CaPZKK5y6XCk0AKNf8SW9e/zRH6xKrBuYMwlHMIMPf6ABssCDH1w9 5nw8qq1WpndIW2nOG8TltGQaiNWxLhPcMCLKbwLEmcPd0emy0J3kS0KGzOc0AMSBtv5T 0SZ+ysld1FpvaRyeBDEpGr9S4o0FP1nppG3fARd9u/ZoDF7YEFl2NW3v61K5MDOwfR9A tuC2ExS5XDHY1WGuhZIrQpSTPm8v8Xjkada9jETPPTtx20X0y3TC506tQg5q/oRBdUCm WHmBfjoJ8EX8kPw+W9WCwm0ElpcPlV0+GFOoAf88Us9LQazfdHF/hZPbN6Kx7vsyWvke ZWww== X-Gm-Message-State: AOAM531vuHCdeGuTWCjDVj9hN2+TjkPnMGxYDldXiMYOL0fTVQ2h8FLx bOm4YIql4Q+nkjT/feZjOatSWCO7UktUO+VTwakskuiFACc= X-Google-Smtp-Source: ABdhPJzEKp6GCKI6Ga+dSn6XV5K06jMwiVUwGPmekGUJJJSi4faP/9Cc5jRamMxGGITykw0PAJgoDwjJZwPJtZnituw= X-Received: by 2002:a4a:b04c:: with SMTP id g12mr7303668oon.3.1628268250600; Fri, 06 Aug 2021 09:44:10 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ac9:704d:0:0:0:0:0 with HTTP; Fri, 6 Aug 2021 09:44:10 -0700 (PDT) In-Reply-To: References: <202107022232.162MWUIY049889@gitrepo.freebsd.org> From: Rob Wing Date: Fri, 6 Aug 2021 08:44:10 -0800 Message-ID: Subject: Re: git: 25392fac9488 - main - libalias: Fix splay comparsion bug To: Gleb Smirnoff Cc: Lutz Donnerhacke , "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" X-Rspamd-Queue-Id: 4GhBC43x18z4rHZ X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; TAGGED_FROM(0.00)[] Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.34 X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Aug 2021 16:44:16 -0000 Hey Gleb, as a heads up (in case you missed it)...about a week ago Lutz mentioned he=E2=80=99d be AFK for three weeks. On Friday, August 6, 2021, Gleb Smirnoff wrote: > Lutz, > > Wouldn't declaring 'i' to u_short fix the root of the problem? > > On Fri, Jul 02, 2021 at 10:32:30PM +0000, Lutz Donnerhacke wrote: > L> The branch main has been updated by donner: > L> > L> URL: https://cgit.FreeBSD.org/src/commit/?id=3D > 25392fac9488bcae5c451500df2e2945430484a6 > L> > L> commit 25392fac9488bcae5c451500df2e2945430484a6 > L> Author: Lutz Donnerhacke > L> AuthorDate: 2021-07-02 21:41:25 +0000 > L> Commit: Lutz Donnerhacke > L> CommitDate: 2021-07-02 22:31:53 +0000 > L> > L> libalias: Fix splay comparsion bug > L> > L> Comparing elements in a tree requires transitiviy. If a < b and b > < c > L> then a must be smaller than c. This way the tree elements are > always > L> pairwise comparable. > L> > L> Tristate comparsion functions returning values lower, equal, or > L> greater than zero, are usually implemented by a simple subtraction > of > L> the operands. If the size of the operands are equal to the size o= f > L> the result, integer modular arithmetics kick in and violates the > L> transitivity. > L> > L> Example: > L> Working on byte with 0, 120, and 240. Now computing the difference= s: > L> 120 - 0 =3D 120 > L> 240 - 120 =3D 120 > L> 240 - 0 =3D -16 > L> > L> MFC after: 3 days > L> sys/netinet/libalias/alias_db.h | 13 +++++++------ > L> 1 file changed, 7 insertions(+), 6 deletions(-) > L> > L> diff --git a/sys/netinet/libalias/alias_db.h > b/sys/netinet/libalias/alias_db.h > L> index ec0b69c01f82..971ca305c1a6 100644 > L> --- a/sys/netinet/libalias/alias_db.h > L> +++ b/sys/netinet/libalias/alias_db.h > L> @@ -351,10 +351,10 @@ static inline int > L> cmp_out(struct alias_link *a, struct alias_link *b) { > L> int i =3D a->src_port - b->src_port; > L> if (i !=3D 0) return (i); > L> - i =3D a->src_addr.s_addr - b->src_addr.s_addr; > L> - if (i !=3D 0) return (i); > L> - i =3D a->dst_addr.s_addr - b->dst_addr.s_addr; > L> - if (i !=3D 0) return (i); > L> + if (a->src_addr.s_addr > b->src_addr.s_addr) return (1); > L> + if (a->src_addr.s_addr < b->src_addr.s_addr) return (-1); > L> + if (a->dst_addr.s_addr > b->dst_addr.s_addr) return (1); > L> + if (a->dst_addr.s_addr < b->dst_addr.s_addr) return (-1); > L> i =3D a->dst_port - b->dst_port; > L> if (i !=3D 0) return (i); > L> i =3D a->link_type - b->link_type; > L> @@ -368,8 +368,9 @@ cmp_in(struct group_in *a, struct group_in *b) { > L> if (i !=3D 0) return (i); > L> i =3D a->link_type - b->link_type; > L> if (i !=3D 0) return (i); > L> - i =3D a->alias_addr.s_addr - b->alias_addr.s_addr; > L> - return (i); > L> + if (a->alias_addr.s_addr > b->alias_addr.s_addr) return (1); > L> + if (a->alias_addr.s_addr < b->alias_addr.s_addr) return (-1); > L> + return (0); > L> } > L> SPLAY_PROTOTYPE(splay_in, group_in, in, cmp_in); > L> > > -- > Gleb Smirnoff >