>From aec59156abbf8472ba201b6c7ca2592f9c10e077 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 3 Nov 2016 18:26:24 -0700
Subject: [PROPOSED] Fix zic bug in systems lacking hard links

Problem and fix reported by Tom Lane in:
http://mm.icann.org/pipermail/tz/2016-November/024472.html
* zic.c (relname): Count "../"s from "/"s in dest, not source.
---
 NEWS  | 2 +-
 zic.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index 39a7126..4eca755 100644
--- a/NEWS
+++ b/NEWS
@@ -10,7 +10,7 @@ Unreleased, experimental changes
   Changes to code
 
     zic no longer mishandles file systems that lack hard links, fixing
-    a bug introduced in 2016g.  (Problem reported by Tom Lane.)
+    bugs introduced in 2016g.  (Problems reported by Tom Lane.)
     Also, when the destination already contains symbolic links, zic
     should now work better on systems where the 'link' system call
     does not follow symbolic links.
diff --git a/zic.c b/zic.c
index ed4991d..b8e8e03 100644
--- a/zic.c
+++ b/zic.c
@@ -804,9 +804,9 @@ relname(char const *from, char const *to)
   for (i = 0; f[i] && f[i] == to[i]; i++)
     if (f[i] == '/')
       dir_len = i + 1;
-  for (; f[i]; i++)
-    dotdots += f[i] == '/' && f[i - 1] != '/';
-  taillen = i - dir_len;
+  for (; to[i]; i++)
+    dotdots += to[i] == '/' && to[i - 1] != '/';
+  taillen = strlen(f + dir_len);
   dotdotetcsize = 3 * dotdots + taillen + 1;
   if (dotdotetcsize <= linksize) {
     if (!result)
-- 
2.7.4

