From d6e2fe49e5499cf92a357a3ff90b16252daf6163 Mon Sep 17 00:00:00 2001
From: Ismael Luceno <ismael@iodev.co.uk>
Date: Thu, 25 Jan 2024 07:56:58 +0100
Subject: [PATCH] Avoid calling catclose with an invalid argument

Causes a segfault with musl 1.2.4 and earlier.

Upstream-Status: Inappropriate
Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
---
 z01.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/z01.c b/z01.c
index 474c88b4704a..58464e834fc1 100644
--- a/z01.c
+++ b/z01.c
@@ -974,7 +974,8 @@ int main(int argc, char *argv[])
   while( run_num <= runs_to_do );
 
 #if LOCALE_ON
-  catclose(MsgCat);
+  if (MsgCat != (nl_catd)-1)
+    catclose(MsgCat);
 #endif
 
   exit(0);
-- 
2.43.0

