>From 70c6bd1841a55441fe8ac4e82350c0f6c68ed28b Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 14 Mar 2019 09:19:20 -0700
Subject: [PATCH] zic: fix bug when -r removes all transitions

Problem reported by Christopher Wong in:
https://mm.icann.org/pipermail/tz/2019-March/027780.html
* zic.c (outzone): Fix core dump when attypes is null.
---
 NEWS  | 3 ++-
 zic.c | 7 ++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index 9ad46b0..78fd896 100644
--- a/NEWS
+++ b/NEWS
@@ -32,7 +32,8 @@ Unreleased, experimental changes
     This helps shrink output size and can be useful for applications
     not needing the full timestamp history, such as TZDIST truncation;
     see Internet RFC 8536 section 5.1.  (Inspired by a feature request
-    from Christopher Wong.)
+    from Christopher Wong, helped along by bug reports from Wong and
+    from Tim Parenti.)
 
   Changes to documentation
 
diff --git a/zic.c b/zic.c
index 6b2f97f..493fb65 100644
--- a/zic.c
+++ b/zic.c
@@ -2849,11 +2849,12 @@ error(_("can't determine time zone abbreviation to use just after until time"));
 		xr.r_dycode = DC_DOM;
 		xr.r_dayofmonth = 1;
 		xr.r_tod = 0;
-		for (lastat = &attypes[0], i = 1; i < timecnt; i++)
+		for (lastat = attypes, i = 1; i < timecnt; i++)
 			if (attypes[i].at > lastat->at)
 				lastat = &attypes[i];
-		if (lastat->at < rpytime(&xr, max_year - 1)) {
-			addtt(rpytime(&xr, max_year + 1), lastat->type);
+		if (!lastat || lastat->at < rpytime(&xr, max_year - 1)) {
+			addtt(rpytime(&xr, max_year + 1),
+			      lastat ? lastat->type : defaulttype);
 			attypes[timecnt - 1].dontmerge = true;
 		}
 	}
-- 
2.20.1

