Index | Thread | Search

From:
"Alvar Penning" <post@0x21.biz>
Subject:
newsyslog
To:
<tech@openbsd.org>
Date:
Wed, 01 Apr 2026 22:41:28 +0200

Download raw body.

Thread
  • Alvar Penning:

    newsyslog

Hi all,

The following diff fixes the incorrect leap year detection within
newsyslog(8), I stumbled across while checking my other diff.

Prior, a year was considered a leap year if
- it is divisible by 4,
- it is NOT divisible by 100 and
- it is divisible by 400.

Unless I am really tired right now, this should be impossible. There
should be no number divisible by 400 but NOT divisible by 100.
Furthermore, enforcing that every leap year must be divisible by 400
makes no real sense.

A more straight forward implementation follows, handling both the
"divisible by 4 and not 100" and the "divisible by 4, 100 and 400" case.

Best,
Alvar


diff --git a/newsyslog.c b/newsyslog.c
index 0be4ed259b9..d4a62194ab3 100644
--- a/newsyslog.c
+++ b/newsyslog.c
@@ -1251,12 +1251,12 @@ parseDWM(char *s)
 
 	nd = mtab[tm.tm_mon];
 
-	if (tm.tm_mon == 1) {
-		if (((tm.tm_year + 1900) % 4 == 0) &&
-		    ((tm.tm_year + 1900) % 100 != 0) &&
-		    ((tm.tm_year + 1900) % 400 == 0)) {
-			nd++;	/* leap year, 29 days in february */
-		}
+	/* leap year, 29 days in february */
+	if ((tm.tm_mon == 1) && ((tm.tm_year + 1900) % 4 == 0)) {
+		if ((tm.tm_year + 1900) % 100 != 0)
+			nd++; /* divisible by 4, not divisible by 100 */
+		else if ((tm.tm_year + 1900) % 400 == 0)
+			nd++; /* divisible by 4, 100 and 400 */
 	}
 	tm.tm_hour = tm.tm_min = tm.tm_sec = 0;