From e84b33b8b9d5367690e26a6b06702969715f8b2e Mon Sep 17 00:00:00 2001 From: christos Date: Fri, 5 Apr 2024 16:56:58 +0000 Subject: [PATCH] break strength ties so that qsort is deterministic --- external/bsd/file/dist/src/apprentice.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/external/bsd/file/dist/src/apprentice.c b/external/bsd/file/dist/src/apprentice.c index 73391082a8e3..38c13b0da782 100644 --- a/external/bsd/file/dist/src/apprentice.c +++ b/external/bsd/file/dist/src/apprentice.c @@ -1,4 +1,4 @@ -/* $NetBSD: apprentice.c,v 1.28 2023/08/18 19:00:11 christos Exp $ */ +/* $NetBSD: apprentice.c,v 1.29 2024/04/05 16:56:58 christos Exp $ */ /* * Copyright (c) Ian F. Darwin 1986-1995. @@ -37,7 +37,7 @@ #if 0 FILE_RCSID("@(#)$File: apprentice.c,v 1.342 2023/07/17 14:38:35 christos Exp $") #else -__RCSID("$NetBSD: apprentice.c,v 1.28 2023/08/18 19:00:11 christos Exp $"); +__RCSID("$NetBSD: apprentice.c,v 1.29 2024/04/05 16:56:58 christos Exp $"); #endif #endif /* lint */ @@ -1141,8 +1141,12 @@ apprentice_sort(const void *a, const void *b) const struct magic_entry *mb = CAST(const struct magic_entry *, b); size_t sa = file_magic_strength(ma->mp, ma->cont_count); size_t sb = file_magic_strength(mb->mp, mb->cont_count); - if (sa == sb) - return 0; + if (sa == sb) { + int x = memcmp(ma->mp, mb->mp, sizeof(*ma->mp)); + if (x == 0) + abort(); + return x > 0 ? -1 : 1; + } else if (sa > sb) return -1; else