Date: Fri, 6 Aug 2021 08:44:10 -0800 From: Rob Wing <rob.fx907@gmail.com> To: Gleb Smirnoff <glebius@freebsd.org> Cc: Lutz Donnerhacke <donner@freebsd.org>, "src-committers@freebsd.org" <src-committers@freebsd.org>, "dev-commits-src-all@freebsd.org" <dev-commits-src-all@freebsd.org>, "dev-commits-src-main@freebsd.org" <dev-commits-src-main@freebsd.org> Subject: Re: git: 25392fac9488 - main - libalias: Fix splay comparsion bug Message-ID: <CAF3%2Bn_fGk%2B-wdMyB94SXSY7n=QWmAhgu62pRD9exhuLrh36TQQ@mail.gmail.com> In-Reply-To: <YQ1Ol7UfATYcXMwa@FreeBSD.org> References: <202107022232.162MWUIY049889@gitrepo.freebsd.org> <YQ1Ol7UfATYcXMwa@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <glebius@freebsd.org> 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 <donner@FreeBSD.org> > L> AuthorDate: 2021-07-02 21:41:25 +0000 > L> Commit: Lutz Donnerhacke <donner@FreeBSD.org> > 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 >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAF3%2Bn_fGk%2B-wdMyB94SXSY7n=QWmAhgu62pRD9exhuLrh36TQQ>