>From 30eba24c77288c65ca0c12b2e9039cd52facb829 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 27 Jul 2019 11:56:47 -0700
Subject: [PROPOSED] Defend against trailing CR in leapseconds.list

Derived from a suggestion by Chris Woodbury in:
https://mm.icann.org/pipermail/tz/2019-July/028382.html
* leapseconds.awk: Strip trailing CR from input lines.
Also, use %d format instead of %s when formatting an integer.
Either format is correct, but %d is clearer.
---
 leapseconds.awk | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/leapseconds.awk b/leapseconds.awk
index 652a45b..af9b231 100755
--- a/leapseconds.awk
+++ b/leapseconds.awk
@@ -61,6 +61,9 @@ BEGIN {
   monthlen[4] = monthlen[6] = monthlen[9] = monthlen[11] = 30
 }
 
+# In case the input has CRLF form a la NIST.
+{ sub(/\r$/, "") }
+
 /^#\tUpdated through/ || /^#\tFile expires on:/ {
     last_lines = last_lines $0 "\n"
 }
@@ -104,7 +107,7 @@ END {
 
     print ""
     print "# POSIX timestamps for the data in this file:"
-    printf "#updated %s\n", updated - epoch_minus_NTP
-    printf "#expires %s\n", expires - epoch_minus_NTP
+    printf "#updated %d\n", updated - epoch_minus_NTP
+    printf "#expires %d\n", expires - epoch_minus_NTP
     printf "\n%s", last_lines
 }
-- 
2.17.1

