[tz] [PROPOSED 1/7] Avoid undefined behavior if no Link lines

Paul Eggert eggert at cs.ucla.edu
Wed Oct 26 04:10:15 UTC 2022


* zic.c (make_links): Don't call qsort(NULL, 0, ...) as this has
undefined behavior in C.  This fixes a bug introduced five days ago.
---
 zic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/zic.c b/zic.c
index 78afa67..a699285 100644
--- a/zic.c
+++ b/zic.c
@@ -683,7 +683,8 @@ static void
 make_links(void)
 {
   ptrdiff_t i, j, nalinks;
-  qsort(links, nlinks, sizeof *links, qsort_linkcmp);
+  if (nlinks)
+    qsort(links, nlinks, sizeof *links, qsort_linkcmp);
 
   /* Ignore each link superseded by a later link with the same name.  */
   j = 0;
-- 
2.37.3



More information about the tz mailing list