Do not use subtraction for comparators, this doesn't really matter for

IDs but it breaks key sorting. GitHub issue 5646 from Alexandre Fiori.

(cherry picked from commit db3950ed07)
This commit is contained in:
nicm
2026-09-28 10:42:01 +00:00
committed by Nicholas Marriott
parent 35c602bc53
commit 0383107696
3 changed files with 50 additions and 26 deletions

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: hyperlinks.c,v 1.5 2026/06/29 16:44:06 nicm Exp $ */
/* $OpenBSD: hyperlinks.c,v 1.6 2026/09/28 10:42:01 nicm Exp $ */
/*
* Copyright (c) 2021 Will <author@will.party>
@@ -87,7 +87,11 @@ hyperlinks_by_uri_cmp(struct hyperlinks_uri *left, struct hyperlinks_uri *right)
return (-1);
if (*right->internal_id != '\0')
return (1);
return (left->inner - right->inner);
if (left->inner < right->inner)
return (-1);
if (left->inner > right->inner)
return (1);
return (0);
}
r = strcmp(left->internal_id, right->internal_id);
@@ -104,7 +108,11 @@ static int
hyperlinks_by_inner_cmp(struct hyperlinks_uri *left,
struct hyperlinks_uri *right)
{
return (left->inner - right->inner);
if (left->inner < right->inner)
return (-1);
if (left->inner > right->inner)
return (1);
return (0);
}
RB_PROTOTYPE_STATIC(hyperlinks_by_inner_tree, hyperlinks_uri, by_inner_entry,
hyperlinks_by_inner_cmp);